﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using nplJobsCommon.JobSeeker;
using nplJobsCommon.Common;
using nplJobsBLL.Common;
using nplJobsCommon.Employeer;
using nplJobsBLL.ProcessJobSeeker;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Services;
using System.IO;
using nplJobsBLL.ProcessSelectJobSeeker;
using Newtonsoft.Json;
using System.Data;
using System.Drawing;
using System.Web.Security;
using nplJobsBLL.ProcessJob;
using Elmah;
using System.Globalization;
using nplJobsDAL.Delete;

public partial class EditProfile : System.Web.UI.Page
{
    public static string ProfilePicPath { get; set; }
    public static List<string> lstSkills;

    protected void Page_Init(object sender, EventArgs e)
    {
        //if (!IsPostBack)
        //txtDateOfBirth.Text = DateTime.Now.ToString("d");
    }

    /// <summary>
    ///This function loads nationality information
    /// </summary>

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            //int i = 0;
            //int j = 100;
            //int a = j / i;

            hdCurrentDate.Value = DateTime.Now.ToString("dd/MM/yyyy");
            if (!Context.User.Identity.IsAuthenticated)
                Response.Redirect("~/Default.aspx");

            if (!IsPostBack)
            {
                Page.Title = "npljobs.com || Edit profile";

                Label lblTitle = Page.Master.FindControl("lblTitle") != null ? (Label)Page.Master.FindControl("lblTitle") : new Label();
                lblTitle.Text = "Edit profile";

                LoadCountry();
                LoadDivision();
                if (HttpContext.Current.Session["UserID"] != null)
                {
                    LoadData();
                }
                else
                {
                    MembershipUser u = Membership.GetUser(User.Identity.Name);
                    HttpContext.Current.Session["UserID"] = u != null ? u.ProviderUserKey : null;
                    LoadData();
                }

                string resumePath = "/UploadedResume";
                string imagePath = "/UploadedImage";

                string _imagePath = Server.MapPath(imagePath);
                string _resumePath = Server.MapPath(resumePath);

                if (!Directory.Exists(_imagePath))
                {
                    Directory.CreateDirectory(_imagePath);
                }
                if (!Directory.Exists(_resumePath))
                {
                    Directory.CreateDirectory(_resumePath);
                }
            }
            else
                lstSkills = hdnSelectedTags.Value != null ? hdnSelectedTags.Value.ToString().Split(new char[] { ',' }).ToList() : null; ;

        }
        catch (System.Threading.ThreadAbortException)
        {
            //ErrorSignal.FromCurrentContext().Raise(ex);
        } //
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }


    #region  LoadLanguageProficiency()
    public List<LanguageProficiency> LoadLanguageProficiency()
    {
        try
        {
            nplJobsBLL.Common.ProcessLanguageProficiency languageProficiency = new nplJobsBLL.Common.ProcessLanguageProficiency();
            languageProficiency.invoke();
            return languageProficiency.LanguageProficiency;
        }
        catch (Exception exp)
        {
            throw new Exception(exp.Message.ToString());
        }
    }
    #endregion

    #region LoadData
    private void LoadData()
    {

        txtDateOfBirth.Text = System.DateTime.Now.ToString("dd/MM/yyyy");
        fvProfessionalInfo.DefaultMode = FormViewMode.ReadOnly;

        LoadGender();
        LoadNationality();
        LoadMaritalStatus();

        JobSeeker jobseeker = new JobSeeker();
        Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();
        ProcessSelectJobSeeker jobSeeker = new ProcessSelectJobSeeker();
        jobSeeker.JobSeekerID = jobseekerID;
        jobSeeker.invoke();
        jobseeker = jobSeeker.JobSeeker != null ? jobSeeker.JobSeeker.Find(j => j.JobSeekerID == jobseekerID) : new JobSeeker();

        if (jobseeker != null)
        {
            LoadJobseeker(jobseeker);

            List<ProfessionalInfo> proInfo = LoadProfessionalInfo(jobseeker);

            if (proInfo != null && proInfo.Count == 0)
            {
                fvProfessionalInfo.DefaultMode = FormViewMode.Insert;
            }
            else
            {
                jobseeker.ProfessionalInfoID = -1;
                BindProfessionalInfo(jobseeker);
            }
            List<EducationInfo> eduInfo = LoadEducationalInfo(jobseeker);
            if (eduInfo != null && eduInfo.Count == 0)
            {
                fvEducationalInfo.DefaultMode = FormViewMode.Insert;
            }
            else
            {
                jobseeker.EducationInfoID = -1;
                BindEducationalInfo(jobseeker);
            }
            jobseeker.EducationInfoID = -1;
        }
    }
    #endregion

    #region LoadJobseeker
    /// <summary>
    /// Load jobseeker by jobseeker id
    /// </summary>
    /// <param name="j"></param>

    private void LoadJobseeker(JobSeeker j)
    {
        try
        {
            txtFirstName.Text = j.FirstName;
            txtLastName.Text = j.LastName;
            txtDateOfBirth.Text = string.Format("{0}/{1}/{2}", j.DOB.Day.ToString("0#"), j.DOB.Month.ToString("0#"), j.DOB.Year); ;

            ddlGender.SelectedValue = j.GenderID == -1 ? "-1" : j.GenderID.ToString();
            ddlNationality.SelectedValue = j.NationalityID == -1 ? "-1" : j.NationalityID.ToString();


            ddlMaritalStatus.SelectedValue = j.MaritalStatusID == 0 ? "-1" : j.MaritalStatusID.ToString();
            ddlGender.SelectedValue = j.GenderID == 0 ? "-1" : j.GenderID.ToString();
            txtAboutMe.Text = j.AboutMe;

            txtPostalAddress.Text = j.PostalAddress;
            txtEmail.Text = j.Email;
            txtAleternativeEmail.Text = j.AlternativeEmail;
            ddlExpectedSalary.SelectedValue = j.ExpectedSalaryID > 0 ? j.ExpectedSalaryID.ToString() : "-1";
            ddlPresentSalary.SelectedValue = j.PresentSalaryID > 0 ? j.PresentSalaryID.ToString() : "-1";
            txtHomePhone.Text = j.HomePhone;
            txtMobilePhone.Text = j.MobilePhone;
            if (j.CountryID == null || j.CountryID == -1)
            {
                ddlCountry.SelectedValue = "140";
            }
            else
            {
                ddlCountry.SelectedValue = j.CountryID.ToString();
            }

            LoadPhoto(j.Photo);

            LoadResume(j.Resume);

            Session["Skills"] = j.Skills;
            lstSkills = Session["Skills"] != null ? Session["Skills"].ToString().Split(new char[] { ',' }).ToList() : null;

            //  Session["Qualifications"] = j.Qualifications;
            string[] quas = j.Qualifications != null ? j.Qualifications.ToString().Split(new char[] { '~' }, StringSplitOptions.RemoveEmptyEntries).ToArray() : null;

            LoadQualifications(quas);

            int jobSeekerProficiencyID = j.JobSeekerProficiencyID;

            List<JobSeekerLanguageProficiency> lstJobSeekerLanguageProficiency = new List<JobSeekerLanguageProficiency>();
            ProcessSelectJobSeekerLanguageProficiency jobSeekerLanguageProficiency = new ProcessSelectJobSeekerLanguageProficiency();
            jobSeekerLanguageProficiency.JobSeekerID = j.JobSeekerID;
            jobSeekerLanguageProficiency.invoke();
            lstJobSeekerLanguageProficiency = jobSeekerLanguageProficiency.JobSeekerLanguageProficiency;
            Session["CurrentLanguages"] = lstJobSeekerLanguageProficiency;

            ddlFluency0.SelectedValue = "-1";
            ddlFluency1.SelectedValue = "-1";
            ddlFluency2.SelectedValue = "-1";
            ddlFluency3.SelectedValue = "-1";
            ddlFluency4.SelectedValue = "-1";

            ddlOtherLanguage0.SelectedValue = "-1";
            ddlOtherLanguage1.SelectedValue = "-1";
            ddlOtherLanguage2.SelectedValue = "-1";
            ddlOtherLanguage3.SelectedValue = "-1";
            ddlOtherLanguage4.SelectedValue = "-1";

            if (lstJobSeekerLanguageProficiency.Count > 0)
            {
                hdOtherLanIDNepali.Value = "0";
                hdOtherLanIDEnglish.Value = "0";

                int languageID = 0, proficiencyID = 0, id = 0;
                List<string> languageProficiency = new List<string>();

                foreach (var jslp in lstJobSeekerLanguageProficiency.Where(l => l.LanguageID == 1 || l.LanguageID == 2))
                {
                    languageID = jslp.LanguageID;
                    proficiencyID = jslp.ProficiencyID;
                    id = jslp.ID;

                    if (languageID == 1) //Nepali
                    {
                        ddlNepali.SelectedValue = proficiencyID.ToString();
                        hdOtherLanIDNepali.Value = !string.IsNullOrEmpty(id.ToString()) ? id.ToString() : "0";
                    }
                    else if (languageID == 2) //English
                    {
                        ddlEnglish.SelectedValue = proficiencyID.ToString();
                        hdOtherLanIDEnglish.Value = !string.IsNullOrEmpty(id.ToString()) ? id.ToString() : "0";
                    }
                }

                Control languageContainer0 = upLanguage.FindControl("languageContainer0");
                Control languageContainer1 = upLanguage.FindControl("languageContainer1");
                Control languageContainer2 = upLanguage.FindControl("languageContainer2");
                Control languageContainer3 = upLanguage.FindControl("languageContainer3");
                Control languageContainer4 = upLanguage.FindControl("languageContainer4");

                hdOtherLanID0.Value = "0";
                hdOtherLanID1.Value = "0";
                hdOtherLanID2.Value = "0";
                hdOtherLanID3.Value = "0";
                hdOtherLanID4.Value = "0";

                int countLanguages = lstJobSeekerLanguageProficiency.Where(l => l.LanguageID > 2).OrderBy(li => li.LanguageID).Count();
                if (countLanguages > 1)
                {
                    if (countLanguages == 2)
                    {
                        languageContainer0.Visible = true;
                        languageContainer1.Visible = true;
                        languageContainer2.Visible = false;
                        languageContainer3.Visible = false;
                        languageContainer4.Visible = false;
                    }
                    if (countLanguages == 3)
                    {
                        languageContainer0.Visible = true;
                        languageContainer1.Visible = true;
                        languageContainer2.Visible = true;
                        languageContainer3.Visible = false;
                        languageContainer4.Visible = false;
                    }
                    else if (countLanguages == 4)
                    {
                        languageContainer0.Visible = true;
                        languageContainer1.Visible = true;
                        languageContainer2.Visible = true;
                        languageContainer3.Visible = true;
                        languageContainer4.Visible = false;
                    }
                    else if (countLanguages == 5)
                    {
                        languageContainer0.Visible = true;
                        languageContainer1.Visible = true;
                        languageContainer2.Visible = true;
                        languageContainer3.Visible = true;
                        languageContainer4.Visible = true;
                    }
                }
                else
                {
                    languageContainer0.Visible = true;
                    languageContainer1.Visible = false;
                    languageContainer2.Visible = false;
                    languageContainer3.Visible = false;
                    languageContainer4.Visible = false;
                }

                int lCount = 0;
                foreach (JobSeekerLanguageProficiency jslp in lstJobSeekerLanguageProficiency.Where(l => l.LanguageID > 2).OrderBy(li => li.LanguageID))
                {
                    if (lCount == 0)
                    {
                        languageContainer0.Visible = true;
                        ddlOtherLanguage0.SelectedValue = jslp.LanguageID.ToString();
                        ddlFluency0.SelectedValue = jslp.ProficiencyID.ToString();
                        hdOtherLanID0.Value = jslp.ID.ToString();
                    }
                    if (lCount == 1)
                    {
                        languageContainer1.Visible = true;
                        ddlOtherLanguage1.SelectedValue = jslp.LanguageID.ToString();
                        ddlFluency1.SelectedValue = jslp.ProficiencyID.ToString();
                        hdOtherLanID1.Value = jslp.ID.ToString();
                    }
                    if (lCount == 2)
                    {
                        languageContainer2.Visible = true;
                        ddlOtherLanguage2.SelectedValue = jslp.LanguageID.ToString();
                        ddlFluency2.SelectedValue = jslp.ProficiencyID.ToString();
                        hdOtherLanID2.Value = jslp.ID.ToString();
                    }
                    if (lCount == 3)
                    {
                        languageContainer3.Visible = true;
                        ddlOtherLanguage3.SelectedValue = jslp.LanguageID.ToString();
                        ddlFluency3.SelectedValue = jslp.ProficiencyID.ToString();
                        hdOtherLanID3.Value = jslp.ID.ToString();
                    }
                    if (lCount == 4)
                    {
                        languageContainer4.Visible = true;
                        ddlOtherLanguage4.SelectedValue = jslp.LanguageID.ToString();
                        ddlFluency4.SelectedValue = jslp.ProficiencyID.ToString();
                        hdOtherLanID4.Value = jslp.ID.ToString();
                    }
                    lCount = lCount + 1;
                }

                //foreach (JobSeekerLanguageProficiency jslp in lstJobSeekerLanguageProficiency.Where(l => l.LanguageID != 1 || l.LanguageID != 2))
                //{

                //    string lp = jslp.ID.ToString() + "-" + languageID.ToString() + "-" + proficiencyID.ToString();
                //    languageProficiency.Add(lp);
                //}

                //if (languageProficiency.Count > 0)
                //{
                //    Session["LanguageProficiency"] = languageProficiency;
                //    languageProficiencies = Session["LanguageProficiency"] != null ? Session["LanguageProficiency"] as List<string> : null;
                //}dd


                ddlDivision.SelectedValue = j.DivisionID == -1 ? "-1" : j.DivisionID.ToString();

                int divisionID = ddlDivision.SelectedValue != null ? int.Parse(ddlDivision.SelectedValue.ToString()) : -1;
                PopulateDistrict(divisionID);

                int div = 0;
                bool b = int.TryParse(j.DistrictID.ToString(), out div);

                PopulateCity(div);

                //int ik = 0;
                //int ssss = 33 / ik;

                ddlDistrict.SelectedValue = j.DistrictID == 0 ? "-1" : j.DistrictID.ToString();
                ddlCity.SelectedValue = j.CityID == 0 ? "-1" : j.CityID.ToString();
                if (!ddlCountry.SelectedItem.Text.Equals("Nepal"))
                {
                    ddlDivision.Enabled = false;
                    ddlDistrict.Enabled = false;
                    ddlCity.Enabled = false;

                    ddlDivision.SelectedIndex = -1;
                    ddlDistrict.SelectedIndex = -1;
                    ddlCity.SelectedIndex = -1;

                    if (ddlDivision.Items.Count > 0)
                    {
                        ddlDivision.SelectedItem.Text = "";
                    }
                    if (ddlDistrict.Items.Count > 0)
                    {
                        ddlDistrict.SelectedItem.Text = "";
                    }
                    if (ddlCity.Items.Count > 0)
                    {
                        ddlCity.SelectedItem.Text = "";
                    }
                }
                //if (!ddlCountry.SelectedItem.Text.Equals("Nepal"))
                //{
                //    ddlDivision.Enabled = false;
                //    ddlDistrict.Enabled = false;
                //    ddlCity.Enabled = false;
                //    if (ddlDivision.Items.Count > 0)
                //    {
                //        ddlDivision.SelectedItem.Text = "";
                //    }
                //    if (ddlDistrict.Items.Count > 0)
                //    {
                //        ddlDistrict.SelectedItem.Text = "";
                //    }
                //    if (ddlCity.Items.Count > 0)
                //    {
                //        ddlCity.SelectedItem.Text = "";
                //    }
                //}
                //else
                //{
                //   // LoadDivision();
                //    ddlDivision.SelectedIndex = -1;

                //    ddlDivision.Enabled = true;
                //    ddlDistrict.Enabled = true;
                //    ddlCity.Enabled = true;
                //}
            }
            else
            {
                languageContainer0.Visible = true;
                languageContainer1.Visible = false;
                languageContainer2.Visible = false;
                languageContainer3.Visible = false;
                languageContainer4.Visible = false;
            }



        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }

    private void LoadPhoto(string photo)
    {
        string candidatePic = string.Empty;
        string imagePath = Helper.ResolveUrl("~/UploadedImage/" + photo);

        string _file = Server.MapPath(imagePath);

        if (string.IsNullOrEmpty(photo) || !File.Exists(_file))
        {
            candidatePic = Helper.ResolveUrl("~/img/candidate-cv-photo.png");
        }
        else
        {
            candidatePic = imagePath;
            Session["UploadedImage"] = photo;
        }

        imgProfilePic.ImageUrl = candidatePic;
    }

    private void LoadResume(string resume)
    {
        if (!string.IsNullOrEmpty(resume))
        {
            string savedPath = Server.MapPath("/UploadedResume/" + resume);
            if (File.Exists(savedPath))
            {
                uploadedResumeLink.Attributes.Add("style", "display:''");
                string resumeUrl = Helper.ResolveUrl("~/JobSeeker/ResumeDownload.ashx?name=" + resume);
                uploadedResumeLink.HRef = "";
                uploadedResumeLink.HRef = resumeUrl;
                uploadedResumeLink.InnerHtml = "Click here to download resume";
                //imgDwnloadResume.Src = Helper.ResolveUrl("~/img/download-resume.png");
                Session["UploadedResume"] = resume;
            }
            else
            {
                //imgDwnloadResume.Src = "";
                uploadedResumeLink.Attributes.Add("style", "display:none");
            }
        }
        else
        {
            uploadedResumeLink.Attributes.Add("style", "display:none");
        }
    }

    [WebMethod]
    public static string LoadResumeOnComplete()
    {
        string resumeUrl = string.Empty;
        string resume = HttpContext.Current.Session["UploadedResume"].ToString();
        if (!string.IsNullOrEmpty(resume))
        {
            string savedPath = HttpContext.Current.Server.MapPath("/UploadedResume/" + resume);
            if (File.Exists(savedPath))
            {
                resumeUrl = Helper.ResolveUrl("~/JobSeeker/ResumeDownload.ashx?name=" + resume);
            }
            else
            {
            }
        }
        else
        {
        }
        return resumeUrl;
    }

    private void LoadQualifications(string[] quas)
    {
        try
        {
            if (quas != null && quas.Count() > 0)
            {
                List<TempQualification> lstTmpQualifications = new List<TempQualification>();

                ClearAllQualification();
                for (int i = 0; i < quas.Count(); i++)
                {
                    if (i == 0)
                    {
                        Control div = (Control)upQualification.FindControl("divQualificationContainer");
                        if (div != null)
                        {
                            div.Visible = true;
                            TextBox txtQualification = (TextBox)div.FindControl("txtQualification");
                            txtQualification.Text = quas[i].ToString();
                            TempQualification qt = new TempQualification();
                            qt.QualificationID = i;
                            qt.Name = quas[i].ToString();
                            lstTmpQualifications.Add(qt);
                        }
                    }
                    else
                    {
                        Control div = (Control)upQualification.FindControl("divQualificationContainer" + i.ToString());
                        if (div != null)
                        {
                            div.Visible = true;
                            TextBox txtQualification = (TextBox)div.FindControl("txtQualification" + i.ToString());
                            txtQualification.Text = quas[i].ToString();
                            TempQualification qt = new TempQualification();
                            qt.QualificationID = i;
                            qt.Name = quas[i].ToString();
                            lstTmpQualifications.Add(qt);
                        }
                    }
                }
                Session["Qualification"] = lstTmpQualifications;
            }
            else
            {
                divQualificationContainer.Visible = true;
                txtQualification.Text = string.Empty;
            }
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }

    private void ClearAllQualification()
    {
        divQualificationContainer.Visible = false;
        txtQualification.Text = string.Empty;
        divQualificationContainer1.Visible = false;
        txtQualification1.Text = string.Empty;
        divQualificationContainer2.Visible = false;
        txtQualification2.Text = string.Empty;
        divQualificationContainer3.Visible = false;
        txtQualification3.Text = string.Empty;
        divQualificationContainer4.Visible = false;
        txtQualification4.Text = string.Empty;
    }

    #endregion

    #region UploadedComplete
    protected void asynPictureUpload_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        string savePath = string.Empty, candidatePic = string.Empty, jobseekerImg = string.Empty;
        try
        {
            string fileName = e.FileName;

            string fileExt = !String.IsNullOrEmpty(fileName) ? Path.GetExtension(fileName).ToLower() : String.Empty;

            int fileSize = Int32.Parse(Path.GetFileName(e.FileSize));

            if (fileSize > 102400) //size in bytes
            {
                return;
            }
            else if (fileSize <= 0) //size in bytes
            {
                return;
            }
            else //send warning
            {
                if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".png")
                {
                    if (Session["UserID"] != null)
                    {
                        string fileExtention = Path.GetExtension(e.FileName);
                        string fName = (HttpContext.Current.Session["UserID"].ToString().Trim()) + "_" +
                                       DateTime.Now.ToString("yyyyMMddHHmmss") + fileExtention;
                        //savePath = Server.MapPath("/UploadedImage/" + Path.GetFileName(e.FileName));
                        savePath = Server.MapPath("/UploadedImage/" + fName);
                        asyncupload.SaveAs(savePath);

                        jobseekerImg = savePath != null ? Path.GetFileName(savePath) : string.Empty;
                    }

                    ProcessUpdateJobSeekerProfilePicture updateProfilePic = new ProcessUpdateJobSeekerProfilePicture();
                    var jobseekerId = HttpContext.Current.Session["UserID"] != null
                        ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString())
                        : Guid.NewGuid();
                    updateProfilePic.JobSeeker = new JobSeeker() { JobSeekerID = jobseekerId, Photo = jobseekerImg };
                    updateProfilePic.invoke();

                    if (updateProfilePic.isSaved > -1)
                    {
                        lblStatus.Text = "Profile picture uploaded successfully";
                        ScriptManager.RegisterStartupScript(this, GetType(), "ClearSaveMsg", "ClearSaveMsg();", true);
                        LoadPhoto(jobseekerImg);
                    }
                }
            }
        }
        catch (System.Threading.ThreadAbortException)
        {
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }
    protected void asynResumeUpload_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        string savePath = string.Empty, fileName, jobseekerResume = string.Empty;
        try
        {
            fileName = e.FileName;
            string fileExt = !String.IsNullOrEmpty(fileName) ? Path.GetExtension(fileName).ToLower() : String.Empty;
            float fileSize = float.Parse(Path.GetFileName(e.FileSize));

            if (fileSize > 307200) //size in bytes
            {
                return;
            }
            else if (fileSize <= 0) //size in bytes
            {
                return;
            }
            else
            {
                if (fileExt == ".doc" || fileExt == ".pdf" || fileExt == ".docx" || fileExt == ".PDF")
                {
                    //savePath = Server.MapPath("~/UploadedResume/" + Path.GetFileName(e.FileName));
                    if (HttpContext.Current.Session["UserID"] != null)
                    {
                        string fileExtention = Path.GetExtension(e.FileName);
                        string fName = (HttpContext.Current.Session["UserID"].ToString().Trim()) + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + fileExtention;
                        savePath = Server.MapPath("~/UploadedResume/" + fName);
                        asynResumeUpload.SaveAs(savePath);

                        jobseekerResume = savePath != null ? Path.GetFileName(savePath) : string.Empty;
                        //if (!string.IsNullOrEmpty(jobseekerResume))
                        //{
                        //    //Session["UploadedImage"] = savePath != null ? Path.GetFileName(savePath) : string.Empty;
                        //    string resumeUrl = Helper.ResolveUrl("~/JobSeeker/ResumeDownload.ashx?name=" + jobseekerResume);
                        //    Session["UploadedResume"] = jobseekerResume;

                        //    uploadedResumeLink.HRef = resumeUrl;
                        //    uploadedResumeLink.InnerHtml = "Click here to download resume";
                        //    uploadedResumeLink.Attributes.Add("style", "display:''");
                        //}
                        //else
                        //{
                        //    uploadedResumeLink.Attributes.Add("style", "display:none");
                        //}

                    }
                }

                ProcessUpdateJobSeekerResume updateResume = new ProcessUpdateJobSeekerResume();
                var jobseekerId = HttpContext.Current.Session["UserID"] != null
                    ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString())
                    : Guid.NewGuid();
                updateResume.JobSeeker = new JobSeeker() { JobSeekerID = jobseekerId, Resume = jobseekerResume };
                updateResume.invoke();

                if (updateResume.isSaved > -1)
                {
                    lblResumeUploadStatus.Text = "Resume uploaded successfully";
                    ScriptManager.RegisterStartupScript(this, GetType(), "ClearSaveMsg", "ClearSaveMsg();", true);
                    LoadResume(jobseekerResume);
                }
            }

        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }
    #endregion

    #region ProfessionalInfo
    protected void fvProfessionalInfo_DataBound(object sender, EventArgs e)
    {
        try
        {
            var drv = (nplJobsCommon.JobSeeker.ProfessionalInfo)fvProfessionalInfo.DataItem;

            if (drv != null)
            {
                DropDownList ddlCareerLevel = (DropDownList)fvProfessionalInfo.FindControl("ddlCareerLevel");
                if (ddlCareerLevel != null)
                {
                    ListItem careerLevel = (ListItem)ddlCareerLevel.Items.FindByValue(drv.CareerLevelID.ToString());
                    if (careerLevel != null)
                    {
                        ((DropDownList)fvProfessionalInfo.FindControl("ddlCareerLevel")).SelectedValue = drv.CareerLevelID.ToString();
                    }
                }

                DropDownList ddlIndustry = (DropDownList)fvProfessionalInfo.FindControl("ddlIndustry");
                if (ddlIndustry != null)
                {
                    ListItem industry = (ListItem)ddlIndustry.Items.FindByValue(drv.IndustryID.ToString());
                    if (industry != null)
                    {
                        ((DropDownList)fvProfessionalInfo.FindControl("ddlIndustry")).SelectedValue = drv.IndustryID.ToString();
                    }
                }

                DropDownList ddlStatus = (DropDownList)fvProfessionalInfo.FindControl("ddlStatus");
                if (ddlStatus != null)
                {
                    ListItem status = (ListItem)ddlIndustry.Items.FindByValue(drv.JobTypeID.ToString());
                    if (status != null)
                    {
                        ((DropDownList)fvProfessionalInfo.FindControl("ddlStatus")).SelectedValue = drv.JobTypeID.ToString();
                    }
                }
                DropDownList ddlCompanySize = (DropDownList)fvProfessionalInfo.FindControl("ddlCompanySize");
                if (ddlCompanySize != null)
                {
                    ListItem companysize = (ListItem)ddlCompanySize.Items.FindByValue(drv.EmployeeRangeID.ToString());
                    if (companysize != null)
                    {
                        ((DropDownList)fvProfessionalInfo.FindControl("ddlCompanySize")).SelectedValue = drv.EmployeeRangeID.ToString();
                    }
                }
                DropDownList ddlOrganizationType = (DropDownList)fvProfessionalInfo.FindControl("ddlOrganizationType");
                if (ddlOrganizationType != null)
                {
                    ListItem organizationtype = (ListItem)ddlOrganizationType.Items.FindByValue(drv.OrganizationTypeID.ToString());
                    if (organizationtype != null)
                    {
                        ((DropDownList)fvProfessionalInfo.FindControl("ddlOrganizationType")).SelectedValue = drv.OrganizationTypeID.ToString();
                    }
                }

            }

        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }
    private void BindProfessionalInfo(JobSeeker js)
    {

        if (js != null)
        {
            List<ProfessionalInfo> pi = LoadProfessionalInfo(js);

            if (pi != null)
            {
                if (pi != null && pi.Count > 0)
                {
                    fvProfessionalInfo.DataSource = pi;
                    fvProfessionalInfo.DataBind();
                }
                else
                {
                    fvProfessionalInfo.DataSource = new List<ProfessionalInfo>();

                    if (fvProfessionalInfo.CurrentMode != FormViewMode.Insert)
                    {
                        if (fvProfessionalInfo.DataItem == null)
                        {
                            fvProfessionalInfo.ChangeMode(FormViewMode.Insert);
                        }
                    }

                    fvProfessionalInfo.DataBind();

                }
            }
        }
    }
    private List<ProfessionalInfo> LoadProfessionalInfo(JobSeeker j)
    {
        List<ProfessionalInfo> pInfoOrdered = new List<ProfessionalInfo>();
        List<ProfessionalInfo> pInfo = new List<ProfessionalInfo>();
        ProcessSelectProfessionalInfo sp = new ProcessSelectProfessionalInfo();

        if (j != null)
        {
            sp.ProfessionalInfoID = j.ProfessionalInfoID;
            sp.JobseekerID = j.JobSeekerID;
            sp.invoke();
            pInfo = sp.ProfessionalInfo;

            if (sp.ProfessionalInfo != null)
            {
                pInfoOrdered = FormatDate(pInfo.OrderBy(p => p.CurrentPosition).ToList());
            }
        }

        return pInfoOrdered != null ? pInfoOrdered.OrderBy(e => e.CurrentPosition ? 0 : 1).ToList() : new List<ProfessionalInfo>();
    }
    private List<ProfessionalInfo> FormatDate(List<ProfessionalInfo> pInfo)
    {
        IFormatProvider culture = new CultureInfo("en-GB", true);
        foreach (var pi in pInfo)
        {
            pi.FromDateFormatted = pi.FromDate.ToString("dd/MM/yyyy", culture);
            pi.ToDateFormatted = pi.ToDate.ToString("dd/MM/yyyy", culture);
        }

        return pInfo;
    }
    protected void fvProfessionalInfo_PreRender(object sender, EventArgs e)
    {
        try
        {

            fvProfessionalInfo = (FormView)upProfessionalInfo.FindControl("fvProfessionalInfo");

            List<ProfessionalInfo> lstProfessionalInfo = new List<ProfessionalInfo>();
            //JobSeeker js = Session["CurrentJobSeekerInfo"] != null ? (JobSeeker)Session["CurrentJobSeekerInfo"] : new JobSeeker();

            JobSeeker js = new JobSeeker();
            Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();
            ProcessSelectJobSeeker jobSeeker = new ProcessSelectJobSeeker();
            jobSeeker.JobSeekerID = jobseekerID;
            jobSeeker.invoke();
            js = jobSeeker.JobSeeker != null ? jobSeeker.JobSeeker.Find(j => j.JobSeekerID == jobseekerID) : new JobSeeker();

            lstProfessionalInfo = LoadProfessionalInfo(js);

            if ((lstProfessionalInfo != null && lstProfessionalInfo.Count == 0) || fvProfessionalInfo.CurrentMode != FormViewMode.ReadOnly)
            {
                if (fvProfessionalInfo.CurrentMode == FormViewMode.Insert)
                {

                    ProfessionalInfoReloadInInsertMode(lstProfessionalInfo);

                }
                else if (fvProfessionalInfo.CurrentMode == FormViewMode.Edit)
                {
                }
                else
                {
                    if (Session["UserID"] != null)
                    {
                        if (js != null)
                        {
                            BindProfessionalInfo(js);
                        }
                    }
                }
            }
            else
            {
                if (Session["UserID"] != null)
                {
                    if (js != null)
                    {
                        BindProfessionalInfo(js);
                    }
                }
            }

        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }

    private void ProfessionalInfoReloadInInsertMode(List<ProfessionalInfo> lstProfessionalInfo)
    {
        TextBox txtStartDate = fvProfessionalInfo.FindControl("txtStartDate") != null ? (TextBox)fvProfessionalInfo.FindControl("txtStartDate") : null;
        if (txtStartDate != null)
            txtStartDate.Text = string.Format("{0}/{1}/{2}", DateTime.Now.Day.ToString("0#"), DateTime.Now.Month.ToString("0#"), DateTime.Now.Year);
        TextBox txtEndDate = fvProfessionalInfo.FindControl("txtEndDate") != null ? (TextBox)fvProfessionalInfo.FindControl("txtEndDate") : null;
        if (txtEndDate != null)
            txtEndDate.Text = string.Format("{0}/{1}/{2}", DateTime.Now.Day.ToString("0#"), DateTime.Now.Month.ToString("0#"), DateTime.Now.Year);

        ImageButton cancelInsertButton = fvProfessionalInfo.FindControl("CancelInsertButton") != null ? (ImageButton)fvProfessionalInfo.FindControl("CancelInsertButton") : null;

        if (cancelInsertButton != null)
        {
            if (lstProfessionalInfo != null && lstProfessionalInfo.Count > 0)
            {
                cancelInsertButton.Visible = true;
            }
            else
            {
                cancelInsertButton.Visible = false;
            }
        }
    }
    protected void fvProfessionalInfo_PageIndexChanging(object sender, FormViewPageEventArgs e)
    {
        try
        {
            fvProfessionalInfo.PageIndex = e.NewPageIndex;
            //JobSeeker js = Session["CurrentJobSeekerInfo"] != null ? (JobSeeker)Session["CurrentJobSeekerInfo"] : new JobSeeker();
            JobSeeker js = new JobSeeker();
            Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();
            ProcessSelectJobSeeker jobSeeker = new ProcessSelectJobSeeker();
            jobSeeker.JobSeekerID = jobseekerID;
            jobSeeker.invoke();
            js = jobSeeker.JobSeeker != null ? jobSeeker.JobSeeker.Find(j => j.JobSeekerID == jobseekerID) : new JobSeeker();

            if (js != null)
                BindProfessionalInfo(js);

        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }
    protected void fvProfessionalInfo_ItemUpdating(object sender, FormViewUpdateEventArgs e)
    {
        HtmlGenericControl lblInsertMsg = null;
        List<ProfessionalInfo> lstProfessionalInfo = new List<ProfessionalInfo>();

        try
        {
            lblSaveMsg.Text = string.Empty;
            lblInsertMsg = (HtmlGenericControl)fvProfessionalInfo.FindControl("lblInsertMsg");
            Page.Validate("valProfesionalInfo");
            if (!Page.IsValid)
            {
                return;
            }

            if (Session["UserID"] != null)
            {
                TextBox txtCompany = (TextBox)fvProfessionalInfo.FindControl("txtCompany");
                TextBox txtTitle = (TextBox)fvProfessionalInfo.FindControl("txtTitle");
                DropDownList ddlCareerLevel = (DropDownList)fvProfessionalInfo.FindControl("ddlCareerLevel");
                TextBox txtHomePage = (TextBox)fvProfessionalInfo.FindControl("txtHomePage");
                TextBox txtStartDate = (TextBox)fvProfessionalInfo.FindControl("txtStartDate");
                TextBox txtEndDate = (TextBox)fvProfessionalInfo.FindControl("txtEndDate");
                TextBox txtResponsibilities = (TextBox)fvProfessionalInfo.FindControl("txtResponsibilities");

                DropDownList ddlIndustry = (DropDownList)fvProfessionalInfo.FindControl("ddlIndustry");
                DropDownList ddlCompanySize = (DropDownList)fvProfessionalInfo.FindControl("ddlCompanySize");
                DropDownList ddlOrganizationType = (DropDownList)fvProfessionalInfo.FindControl("ddlOrganizationType");
                DropDownList ddlStatus = (DropDownList)fvProfessionalInfo.FindControl("ddlStatus");
                CheckBox chkCurrentPosition = (CheckBox)fvProfessionalInfo.FindControl("chkCurrentPosition");
                TextBox txtAddress = (TextBox)fvProfessionalInfo.FindControl("txtAddress");


                Guid jobseekerId = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();
                //JobSeeker js = Session["CurrentJobSeekerInfo"] != null ? (JobSeeker)Session["CurrentJobSeekerInfo"] : new JobSeeker();
                JobSeeker js = new JobSeeker();
                Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();
                ProcessSelectJobSeeker jobSeeker = new ProcessSelectJobSeeker();
                jobSeeker.JobSeekerID = jobseekerID;
                jobSeeker.invoke();
                js = jobSeeker.JobSeeker != null ? jobSeeker.JobSeeker.Find(j => j.JobSeekerID == jobseekerID) : new JobSeeker();

                lstProfessionalInfo = LoadProfessionalInfo(js);

                ProfessionalInfo professionalInfo = new ProfessionalInfo();
                professionalInfo.JobSeekerID = jobseekerId;

                if (lstProfessionalInfo != null && lstProfessionalInfo.Count > 0)
                {
                    long professionalInfoId = fvProfessionalInfo.DataKey["ProfessionalInfoID"] != null ? long.Parse(fvProfessionalInfo.DataKey["ProfessionalInfoID"].ToString()) : 0;

                    ProfessionalInfo pf = lstProfessionalInfo.Find(p => p.JobSeekerID == professionalInfo.JobSeekerID && p.ProfessionalInfoID == professionalInfoId);

                    if (pf != null)
                    {

                        if (chkCurrentPosition.Checked)
                        {
                            int count = lstProfessionalInfo.Count(po => po.JobSeekerID == professionalInfo.JobSeekerID && po.ProfessionalInfoID == professionalInfoId && po.CurrentPosition == chkCurrentPosition.Checked);
                            //bool isCurrentAssigned = chkCurrentPosition.Checked;//lstProfessionalInfo.Exists(c => c.CurrentPosition == true);

                            if (lstProfessionalInfo != null && (count == 1))
                            {
                                lblInsertMsg.Visible = true;
                                lblInsertMsg.InnerText = string.Empty;

                                if (txtCompany != null) pf.CompanyName = txtCompany.Text;
                                if (txtTitle != null) pf.Title = txtTitle.Text;
                                if (ddlCareerLevel != null) pf.CareerLevelID = int.Parse(ddlCareerLevel.SelectedValue);
                                if (txtHomePage != null) pf.CompanyHomePage = txtHomePage.Text;
                                if (txtStartDate != null) pf.FromDate = DateTime.ParseExact(txtStartDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                                if (txtEndDate != null) pf.ToDate = DateTime.ParseExact(txtEndDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                                if (txtResponsibilities != null) pf.PositionDescription = txtResponsibilities.Text;
                                if (chkCurrentPosition != null) pf.CurrentPosition = chkCurrentPosition.Checked;

                                if (ddlIndustry != null) pf.IndustryID = int.Parse(ddlIndustry.SelectedValue);
                                if (ddlCompanySize != null) pf.EmployeeRangeID = int.Parse(ddlCompanySize.SelectedValue);
                                if (ddlOrganizationType != null) pf.OrganizationTypeID = int.Parse(ddlOrganizationType.SelectedValue);
                                if (ddlStatus != null) pf.JobTypeID = int.Parse(ddlStatus.SelectedValue);
                                if (txtAddress != null) pf.Address = txtAddress.Text;

                                ProcessInsertJobSeekerProfessionalInfo pii = new ProcessInsertJobSeekerProfessionalInfo();
                                pf.JobSeekerID = jobseekerId;
                                pii.ProfessionalInfo = pf;
                                pii.invoke();

                                if (pf.ProfessionalInfoID > -1)
                                {
                                    ScriptManager.RegisterStartupScript(this, GetType(), "ClearProfessoinalInfo", "InfoUpdate('Entry updated successfully','ctl00_MainContent_fvProfessionalInfo_lblInsertMsg','green');", true);
                                }

                                fvProfessionalInfo.ChangeMode(FormViewMode.ReadOnly);

                                if (js != null)
                                    BindProfessionalInfo(js);
                            }
                            else
                            {
                                lblInsertMsg.Visible = true;

                                if (lblInsertMsg != null)
                                {

                                    ScriptManager.RegisterStartupScript(this, GetType(), "ClearProfessoinalInfo", "InfoUpdate('Current position already assigned.Please try again','ctl00_MainContent_fvProfessionalInfo_lblInsertMsg','red');", true);

                                }
                            }
                        }
                        else
                        {
                            //int count = lstProfessionalInfo.Count(po => po.JobSeekerID == professionalInfo.JobSeekerID && po.ProfessionalInfoID == professionalInfoID && po.CurrentPosition == chkCurrentPosition.Checked);

                            if (lstProfessionalInfo != null)
                            {
                                lblInsertMsg.Visible = true;
                                lblInsertMsg.InnerText = string.Empty;

                                if (txtCompany != null) pf.CompanyName = txtCompany.Text;
                                if (txtTitle != null) pf.Title = txtTitle.Text;
                                if (ddlCareerLevel != null) pf.CareerLevelID = int.Parse(ddlCareerLevel.SelectedValue);
                                if (txtHomePage != null) pf.CompanyHomePage = txtHomePage.Text;
                                if (txtStartDate != null) pf.FromDate = DateTime.ParseExact(txtStartDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                                if (txtEndDate != null) pf.ToDate = DateTime.ParseExact(txtEndDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                                if (txtResponsibilities != null) pf.PositionDescription = txtResponsibilities.Text;

                                if (ddlIndustry != null) pf.IndustryID = int.Parse(ddlIndustry.SelectedValue);
                                if (ddlCompanySize != null) pf.EmployeeRangeID = int.Parse(ddlCompanySize.SelectedValue);
                                if (ddlOrganizationType != null) pf.OrganizationTypeID = int.Parse(ddlOrganizationType.SelectedValue);
                                if (ddlStatus != null) pf.JobTypeID = int.Parse(ddlStatus.SelectedValue);
                                if (chkCurrentPosition != null) pf.CurrentPosition = chkCurrentPosition.Checked;
                                if (txtAddress != null) pf.Address = txtAddress.Text;

                                ProcessInsertJobSeekerProfessionalInfo pii = new ProcessInsertJobSeekerProfessionalInfo();
                                pf.JobSeekerID = jobseekerId;
                                pii.ProfessionalInfo = pf;
                                pii.invoke();

                                if (pf.ProfessionalInfoID > -1)
                                {
                                    ScriptManager.RegisterStartupScript(this, GetType(), "ClearProfessoinalInfo", "InfoUpdate('Entry updated successfully','ctl00_MainContent_fvProfessionalInfo_lblInsertMsg','green');", true);
                                }
                                fvProfessionalInfo.ChangeMode(FormViewMode.ReadOnly);

                                if (js != null)
                                    BindProfessionalInfo(js);
                            }
                            else
                            {
                                lblInsertMsg.Visible = true;

                                if (lblInsertMsg != null)
                                {
                                    ScriptManager.RegisterStartupScript(this, GetType(), "ClearProfessoinalInfo", "InfoUpdate('Current position already assigned.Please try again','ctl00_MainContent_fvProfessionalInfo_lblInsertMsg','red');", true);

                                }
                            }
                        }

                    }//
                }
            }
        }
        catch (Exception ex)
        {
            ScriptManager.RegisterStartupScript(this, GetType(), "ClearProfessoinalInfo", "InfoUpdate('Update error','ctl00_MainContent_fvProfessionalInfo_lblInsertMsg','red');", true);

            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }
    protected void fvProfessionalInfo_ModeChanging(object sender, FormViewModeEventArgs e)
    {
        //JobSeeker js = Session["CurrentJobSeekerInfo"] != null ? (JobSeeker)Session["CurrentJobSeekerInfo"] : new JobSeeker();
        JobSeeker js = new JobSeeker();
        Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();
        ProcessSelectJobSeeker jobSeeker = new ProcessSelectJobSeeker();
        jobSeeker.JobSeekerID = jobseekerID;
        jobSeeker.invoke();
        js = jobSeeker.JobSeeker != null ? jobSeeker.JobSeeker.Find(j => j.JobSeekerID == jobseekerID) : new JobSeeker();

        if (e.NewMode.ToString() == "Edit")
        {
            fvProfessionalInfo.ChangeMode(e.NewMode);
        }
        else if (e.NewMode.ToString() == "Insert")
        {
            fvProfessionalInfo.ChangeMode(e.NewMode);
        }
        else
            fvProfessionalInfo.ChangeMode(e.NewMode);

        if (js != null)
            BindProfessionalInfo(js);
    }
    protected void btnYes_Click(object sender, ImageClickEventArgs e)
    {
        HtmlGenericControl lblInsertMsg = (HtmlGenericControl)fvProfessionalInfo.FindControl("lblInsertMsg");
        List<ProfessionalInfo> lstProfessionalInfo = new List<ProfessionalInfo>();

        try
        {
            Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();

            if (Session["UserID"] != null)
            {
                ProfessionalInfo professionalInfo = new ProfessionalInfo();
                professionalInfo.JobSeekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();


                //JobSeeker js = Session["CurrentJobSeekerInfo"] != null ? (JobSeeker)Session["CurrentJobSeekerInfo"] : new JobSeeker();
                JobSeeker js = new JobSeeker();
                //Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();
                ProcessSelectJobSeeker jobSeeker = new ProcessSelectJobSeeker();
                jobSeeker.JobSeekerID = jobseekerID;
                jobSeeker.invoke();
                js = jobSeeker.JobSeeker != null ? jobSeeker.JobSeeker.Find(j => j.JobSeekerID == jobseekerID) : new JobSeeker();

                lstProfessionalInfo = LoadProfessionalInfo(js);

                if (lstProfessionalInfo != null && lstProfessionalInfo.Count > 0)
                {
                    HiddenField hdProfessionalInfoID = fvProfessionalInfo.FindControl("hdProfessionalInfoID") != null ? (HiddenField)fvProfessionalInfo.FindControl("hdProfessionalInfoID") : null;
                    long professionalInfoID = hdProfessionalInfoID != null && !string.IsNullOrEmpty(hdProfessionalInfoID.Value) ? long.Parse(hdProfessionalInfoID.Value) : 0;
                    ProfessionalInfo pf = lstProfessionalInfo.Find(p => p.JobSeekerID == professionalInfo.JobSeekerID && p.ProfessionalInfoID == professionalInfoID);

                    if (pf != null)
                    {

                        DeleteJobSeekerProfessionalInfo dpi = new DeleteJobSeekerProfessionalInfo();
                        dpi.ProfessionalInfoID = pf.ProfessionalInfoID;
                        dpi.invoke();
                        bool isDeleted = dpi.isDeleted;

                        if (isDeleted)
                        {
                            lstProfessionalInfo.Remove(pf);

                            ModalPopupExtender1.Hide();

                            ScriptManager.RegisterStartupScript(this, GetType(), "ClearProfessoinalInfo", "ClearInfo('Entry deleted successfully','ctl00_MainContent_fvProfessionalInfo_lblInsertMsg');", true);
                        }

                        if (js != null)
                        {
                            BindProfessionalInfo(js);
                            fvProfessionalInfo.ChangeMode(FormViewMode.ReadOnly);
                        }
                    }

                    if (lstProfessionalInfo != null && lstProfessionalInfo.Count > 0)
                    {
                        fvProfessionalInfo.ChangeMode(FormViewMode.ReadOnly);
                    }
                    else
                    {
                        fvProfessionalInfo.ChangeMode(FormViewMode.Insert);
                        ProfessionalInfoReloadInInsertMode(lstProfessionalInfo);
                    }
                }

            }




        }
        catch (Exception ex)
        {
            lblInsertMsg.Attributes.Add("style", "float:right;color: red;");
            ScriptManager.RegisterStartupScript(this, GetType(), "ClearProfessoinalInfo", "ClearProfessoinalInfo('Data updating error');", true);
            ErrorSignal.FromCurrentContext().Raise(ex);
        }

    }
    protected void fvProfessionalInfo_ItemDeleting(object sender, FormViewDeleteEventArgs e)
    {
        List<ProfessionalInfo> lstProfessionalInfo = new List<ProfessionalInfo>();

        try
        {
            lblSaveMsg.Text = string.Empty;
            if (Session["UserID"] != null)
            {
                ProfessionalInfo professionalInfo = new ProfessionalInfo();
                professionalInfo.JobSeekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();

                //JobSeeker js = Session["CurrentJobSeekerInfo"] != null ? (JobSeeker)Session["CurrentJobSeekerInfo"] : new JobSeeker();
                JobSeeker js = new JobSeeker();
                Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();
                ProcessSelectJobSeeker jobSeeker = new ProcessSelectJobSeeker();
                jobSeeker.JobSeekerID = jobseekerID;
                jobSeeker.invoke();
                js = jobSeeker.JobSeeker != null ? jobSeeker.JobSeeker.Find(j => j.JobSeekerID == jobseekerID) : new JobSeeker();

                lstProfessionalInfo = LoadProfessionalInfo(js);

                if (lstProfessionalInfo != null && lstProfessionalInfo.Count > 0)
                {
                    HiddenField hdProfessionalInfoID = fvProfessionalInfo.FindControl("hdProfessionalInfoID") != null ? (HiddenField)fvProfessionalInfo.FindControl("hdProfessionalInfoID") : null;

                    long professionalInfoID = hdProfessionalInfoID != null && !string.IsNullOrEmpty(hdProfessionalInfoID.Value) ? long.Parse(hdProfessionalInfoID.Value) : 0;

                    ProfessionalInfo pf = lstProfessionalInfo.Find(p => p.JobSeekerID == professionalInfo.JobSeekerID && p.ProfessionalInfoID == professionalInfoID);

                    if (pf != null)
                    {
                        lblText.InnerHtml = "Are you sure you want to delete ? <br/> " + pf.CompanyName;
                        ModalPopupExtender1.Show();
                    }

                }
            }
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }
    protected void fvProfessionalInfo_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        HtmlGenericControl lblInsertMsg = (HtmlGenericControl)fvProfessionalInfo.FindControl("lblInsertMsg");
        List<ProfessionalInfo> lstProfessionalInfo = new List<ProfessionalInfo>();

        try
        {
            lblSaveMsg.Text = string.Empty;
            Page.Validate("valProfesionalInfo");
            if (!Page.IsValid)
            {
                return;
            }

            if (Session["UserID"] != null)
            {
                TextBox txtCompany = (TextBox)fvProfessionalInfo.FindControl("txtCompany");
                TextBox txtTitle = (TextBox)fvProfessionalInfo.FindControl("txtTitle");
                DropDownList ddlCareerLevel = (DropDownList)fvProfessionalInfo.FindControl("ddlCareerLevel");
                TextBox txtHomePage = (TextBox)fvProfessionalInfo.FindControl("txtHomePage");
                TextBox txtStartDate = (TextBox)fvProfessionalInfo.FindControl("txtStartDate");
                TextBox txtEndDate = (TextBox)fvProfessionalInfo.FindControl("txtEndDate");
                TextBox txtResponsibilities = (TextBox)fvProfessionalInfo.FindControl("txtResponsibilities");

                DropDownList ddlIndustry = (DropDownList)fvProfessionalInfo.FindControl("ddlIndustry");
                DropDownList ddlCompanySize = (DropDownList)fvProfessionalInfo.FindControl("ddlCompanySize");
                DropDownList ddlOrganizationType = (DropDownList)fvProfessionalInfo.FindControl("ddlOrganizationType");
                DropDownList ddlStatus = (DropDownList)fvProfessionalInfo.FindControl("ddlStatus");
                CheckBox chkCurrentPosition = (CheckBox)fvProfessionalInfo.FindControl("chkCurrentPosition");
                TextBox txtAddress = (TextBox)fvProfessionalInfo.FindControl("txtAddress");

                ProfessionalInfo professionalInfo = new ProfessionalInfo();
                professionalInfo.JobSeekerID = Guid.Parse(HttpContext.Current.Session["UserID"].ToString());

                professionalInfo.IsDeleted = false;
                if (txtCompany != null) professionalInfo.CompanyName = txtCompany.Text.Trim();
                if (txtTitle != null) professionalInfo.Title = txtTitle.Text.Trim();
                if (ddlCareerLevel != null) professionalInfo.CareerLevelID = int.Parse(ddlCareerLevel.SelectedValue);
                if (txtHomePage != null) professionalInfo.CompanyHomePage = txtHomePage.Text;
                if (txtStartDate != null) professionalInfo.FromDate = DateTime.ParseExact(txtStartDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                if (txtEndDate != null) professionalInfo.ToDate = DateTime.ParseExact(txtEndDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                if (txtResponsibilities != null) professionalInfo.PositionDescription = txtResponsibilities.Text;

                if (ddlIndustry != null) professionalInfo.IndustryID = int.Parse(ddlIndustry.SelectedValue);
                if (ddlCompanySize != null) professionalInfo.EmployeeRangeID = int.Parse(ddlCompanySize.SelectedValue);
                if (ddlOrganizationType != null) professionalInfo.OrganizationTypeID = int.Parse(ddlOrganizationType.SelectedValue);
                if (ddlStatus != null) professionalInfo.JobTypeID = int.Parse(ddlStatus.SelectedValue);
                if (chkCurrentPosition != null) professionalInfo.CurrentPosition = chkCurrentPosition.Checked;
                if (txtAddress != null) professionalInfo.Address = txtAddress.Text;

                //Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();

                //JobSeeker js = Session["CurrentJobSeekerInfo"] != null ? (JobSeeker)Session["CurrentJobSeekerInfo"] : new JobSeeker();
                JobSeeker js = new JobSeeker();
                Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();
                ProcessSelectJobSeeker jobSeeker = new ProcessSelectJobSeeker();
                jobSeeker.JobSeekerID = jobseekerID;
                jobSeeker.invoke();
                js = jobSeeker.JobSeeker != null ? jobSeeker.JobSeeker.Find(j => j.JobSeekerID == jobseekerID) : new JobSeeker();

                lstProfessionalInfo = LoadProfessionalInfo(js);

                if (lstProfessionalInfo != null && !lstProfessionalInfo.Exists(po => po.CompanyName == txtCompany.Text.Trim() && po.Title == txtTitle.Text.Trim()))
                {
                    if (lstProfessionalInfo != null && !lstProfessionalInfo.Exists(po => chkCurrentPosition.Checked == true && po.CurrentPosition == chkCurrentPosition.Checked))
                    {
                        lblInsertMsg.Visible = true;
                        lblInsertMsg.InnerText = string.Empty;

                        lstProfessionalInfo.Add(professionalInfo);

                        ProcessInsertJobSeekerProfessionalInfo pii = new ProcessInsertJobSeekerProfessionalInfo();
                        professionalInfo.JobSeekerID = jobseekerID;
                        pii.ProfessionalInfo = professionalInfo;
                        pii.invoke();

                        if (pii.LastJobSeekerProfessionalInfoID > -1)
                        {
                            lblInsertMsg.InnerHtml = "Entry inserted successfully";
                            lblInsertMsg.Attributes.Add("style", "float:right;color: green;");
                            ScriptManager.RegisterStartupScript(this, GetType(), "ClearProfessoinalInfo", "ClearInfo('Entry inserted successfully','ctl00_MainContent_fvProfessionalInfo_lblInsertMsg');", true);
                        }

                        fvProfessionalInfo.ChangeMode(FormViewMode.ReadOnly);

                        if (js != null)
                            BindProfessionalInfo(js);
                    }
                    else
                    {
                        if (lblInsertMsg != null)
                        {
                            ScriptManager.RegisterStartupScript(this, GetType(), "ClearProfessoinalInfo", "InfoUpdate('Current position already assigned.Please try again','ctl00_MainContent_fvProfessionalInfo_lblInsertMsg','red');", true);
                        }
                    }
                }
                else
                {
                    lblInsertMsg.Visible = true;

                    if (lblInsertMsg != null)
                    {
                        lblInsertMsg.InnerText = "Already exists";
                        lblInsertMsg.Attributes.Add("style", "float:right;color: red;");
                    }
                }
            }
        }
        catch (Exception ex)
        {
            ScriptManager.RegisterStartupScript(this, GetType(), "ClearProfessoinalInfo", "InfoUpdate('Data insert error.Please try again','ctl00_MainContent_fvProfessionalInfo_lblInsertMsg','red');", true);
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }

    #endregion

    #region Education Info
    private void BindEducationalInfo(JobSeeker js)
    {
        List<EducationInfo> lstEducation = LoadEducationalInfo(js);

        if (lstEducation != null && lstEducation.Count > 0)
        {
            fvEducationalInfo.DataSource = lstEducation;
            fvEducationalInfo.DataBind();
        }
        else
        {
            fvEducationalInfo.DataSource = new List<EducationInfo>();

            if (fvEducationalInfo.CurrentMode != FormViewMode.Insert)
            {
                if (fvEducationalInfo.DataItem == null)
                {
                    fvEducationalInfo.ChangeMode(FormViewMode.Insert);
                }
            }

            fvEducationalInfo.DataBind();
        }
    }
    private List<EducationInfo> LoadEducationalInfo(JobSeeker j)
    {
        List<EducationInfo> eiInfo = new List<EducationInfo>();
        ProcessSelectEducationalInfo ei = new ProcessSelectEducationalInfo();

        if (j != null)
        {
            ei.EducationalInfoID = j.EducationInfoID;
            ei.JobseekerID = j.JobSeekerID;
            ei.invoke();
            eiInfo = ei.EducationalInfo;

            if (ei.EducationalInfo != null)
            {
                FormatEducationInfoDate(eiInfo);
            }
        }
        return eiInfo;
    }
    private List<EducationInfo> FormatEducationInfoDate(List<EducationInfo> eiInfo)
    {
        eiInfo.OrderBy(ed => ed.DisplayAtTop == true).ThenBy(edu => edu.Degree);
        IFormatProvider culture = new CultureInfo("en-GB", true);
        foreach (var ei in eiInfo)
        {
            DateTime startDate, endDate;

            DateTime.TryParse(ei.FromDate.ToString(), out startDate);
            DateTime.TryParse(ei.ToDate.ToString(), out endDate);

            ei.FromDateFormatted = startDate.ToString("dd/MM/yyyy", culture);
            ei.ToDateFormatted = endDate.ToString("dd/MM/yyyy", culture);
        }

        return eiInfo;
    }
    protected void fvEducationalInfo_PreRender(object sender, EventArgs e)
    {
        //JobSeeker js = Session["CurrentJobSeekerInfo"] != null ? (JobSeeker)Session["CurrentJobSeekerInfo"] : new JobSeeker();
        JobSeeker js = new JobSeeker();
        Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();
        ProcessSelectJobSeeker jobSeeker = new ProcessSelectJobSeeker();
        jobSeeker.JobSeekerID = jobseekerID;
        jobSeeker.invoke();
        js = jobSeeker.JobSeeker != null ? jobSeeker.JobSeeker.Find(j => j.JobSeekerID == jobseekerID) : new JobSeeker();


        if (fvEducationalInfo.CurrentMode == FormViewMode.Insert)
        {
            EductionInfoReloadInInsertMode(js);
        }
        else if (fvEducationalInfo.CurrentMode == FormViewMode.Edit)
        {
        }
        else
        {
            if (js != null)
            {
                BindEducationalInfo(js);
            }
        }
    }

    private void EductionInfoReloadInInsertMode(JobSeeker js)
    {
        TextBox txtEduStartDate = (TextBox)fvEducationalInfo.FindControl("txtEduStartDate");
        txtEduStartDate.Text = string.Format("{0}/{1}/{2}", DateTime.Now.Day.ToString("0#"), DateTime.Now.Month.ToString("0#"), DateTime.Now.Year);
        TextBox txtEduEndDate = (TextBox)fvEducationalInfo.FindControl("txtEduEndDate");
        txtEduEndDate.Text = string.Format("{0}/{1}/{2}", DateTime.Now.Day.ToString("0#"), DateTime.Now.Month.ToString("0#"), DateTime.Now.Year);

        List<EducationInfo> lstEducation = LoadEducationalInfo(js);

        ImageButton CancelInsertButton = (ImageButton)fvEducationalInfo.FindControl("CancelInsertButton");
        if (CancelInsertButton != null)
        {
            if (lstEducation != null && lstEducation.Count > 0)
            {
                if (lstEducation != null && lstEducation.Count > 0)
                {
                    CancelInsertButton.Visible = true;
                }
                else
                {
                    CancelInsertButton.Visible = false;
                }
            }
            else
            {
                if (CancelInsertButton != null)
                {
                    CancelInsertButton.Visible = false;
                }
            }
        }
    }
    protected void fvEducationalInfo_PageIndexChanging(object sender, FormViewPageEventArgs e)
    {
        //fvEducationalInfo.PageIndex = e.NewPageIndex;

        //if (Session["UserID"] != null)
        //{
        //    JobSeeker jobseeker = new JobSeeker();
        //    Guid jobseekerID = Guid.Parse(HttpContext.Current.Session["UserID"].ToString());
        //    ProcessSelectJobSeeker jobSeeker = new ProcessSelectJobSeeker();
        //    jobSeeker.JobSeekerID = jobseekerID;
        //    jobSeeker.invoke();
        //    jobseeker = jobSeeker.JobSeeker.FirstOrDefault();

        //    if (jobseeker != null)
        //    {
        //        BindEducationalInfo(jobseeker);
        //    }
        //}
        fvEducationalInfo.PageIndex = e.NewPageIndex;
        //JobSeeker js = Session["CurrentJobSeekerInfo"] != null ? (JobSeeker)Session["CurrentJobSeekerInfo"] : new JobSeeker();
        JobSeeker js = new JobSeeker();
        Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();
        ProcessSelectJobSeeker jobSeeker = new ProcessSelectJobSeeker();
        jobSeeker.JobSeekerID = jobseekerID;
        jobSeeker.invoke();
        js = jobSeeker.JobSeeker != null ? jobSeeker.JobSeeker.Find(j => j.JobSeekerID == jobseekerID) : new JobSeeker();


        if (js != null)
        {
            if (js != null)
            {
                BindEducationalInfo(js);
            }
        }
    }
    protected void fvEducationalInfo_ModeChanging(object sender, FormViewModeEventArgs e)
    {
        //if (e.NewMode == FormViewMode.Edit)
        //    fvEducationalInfo.ChangeMode(e.NewMode);
        //else if (e.NewMode == FormViewMode.Insert)
        //    fvEducationalInfo.ChangeMode(e.NewMode);
        //else
        //    fvEducationalInfo.ChangeMode(e.NewMode);


        ////lblMsgEduInfo.Text = string.Empty;

        //JobSeeker js = new JobSeeker();
        //if (HttpContext.Current.Session["UserID"] != null)
        //{
        //    Guid jobseekerID = Guid.Parse(HttpContext.Current.Session["UserID"].ToString());
        //    ProcessSelectJobSeeker jobSeeker = new ProcessSelectJobSeeker();
        //    jobSeeker.JobSeekerID = jobseekerID;
        //    jobSeeker.invoke();
        //    js = jobSeeker.JobSeeker.FirstOrDefault();

        //    if (js != null)
        //        BindEducationalInfo(js);
        //}
        //JobSeeker js = Session["CurrentJobSeekerInfo"] != null ? (JobSeeker)Session["CurrentJobSeekerInfo"] : new JobSeeker();
        JobSeeker js = new JobSeeker();
        Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();
        ProcessSelectJobSeeker jobSeeker = new ProcessSelectJobSeeker();
        jobSeeker.JobSeekerID = jobseekerID;
        jobSeeker.invoke();
        js = jobSeeker.JobSeeker != null ? jobSeeker.JobSeeker.Find(j => j.JobSeekerID == jobseekerID) : new JobSeeker();


        if (e.NewMode.ToString() == "Edit")
        {
            fvEducationalInfo.ChangeMode(e.NewMode);
        }
        else if (e.NewMode.ToString() == "Insert")
        {
            fvEducationalInfo.ChangeMode(e.NewMode);
        }
        else
            fvEducationalInfo.ChangeMode(e.NewMode);

        if (js != null)
            BindEducationalInfo(js);
    }
    protected void fvEducationalInfo_ItemDeleting(object sender, FormViewDeleteEventArgs e)
    {
        try
        {

            lblSaveMsg.Text = string.Empty;

            if (Session["UserID"] != null)
            {
                //Page.Validate("valEducationalInfo");

                //if (!Page.IsValid)
                //    return;

                EducationInfo educationInfo = new EducationInfo();
                educationInfo.JobSeekerID = Guid.Parse(HttpContext.Current.Session["UserID"].ToString());
                //JobSeeker js = Session["CurrentJobSeekerInfo"] != null ? (JobSeeker)Session["CurrentJobSeekerInfo"] : new JobSeeker();
                JobSeeker js = new JobSeeker();
                Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();
                ProcessSelectJobSeeker jobSeeker = new ProcessSelectJobSeeker();
                jobSeeker.JobSeekerID = jobseekerID;
                jobSeeker.invoke();
                js = jobSeeker.JobSeeker != null ? jobSeeker.JobSeeker.Find(j => j.JobSeekerID == jobseekerID) : new JobSeeker();

                List<EducationInfo> lstEducationInfo = LoadEducationalInfo(js);

                if (lstEducationInfo != null && lstEducationInfo.Count > 0)
                {
                    HiddenField hdEducationInfoID = fvEducationalInfo.FindControl("hdEducationInfoID") != null ? (HiddenField)fvEducationalInfo.FindControl("hdEducationInfoID") : null;
                    long educationInfoID = hdEducationInfoID != null && !string.IsNullOrEmpty(hdEducationInfoID.Value) ? long.Parse(hdEducationInfoID.Value) : 0;

                    EducationInfo edi = lstEducationInfo.Find(ei => ei.JobSeekerID == educationInfo.JobSeekerID && ei.EducationInfoID == educationInfoID);
                    if (edi != null)
                    {
                        lblEducationInfoText.InnerHtml = "Are you sure you want to delete ? <br/> " + edi.InstitutionName;
                        ModalPopupExtender2.Show();
                    }
                }
            }
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }

    }
    protected void fvEducationalInfo_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        JobSeeker jobseeker = new JobSeeker();
        HtmlGenericControl lblInsertMsg = null;
        EducationInfo educationInfo = new EducationInfo();
        List<EducationInfo> lstEducationInfo = new List<EducationInfo>();
        lblSaveMsg.Text = string.Empty;

        try
        {
            //JobSeeker js = Session["CurrentJobSeekerInfo"] != null ? (JobSeeker)Session["CurrentJobSeekerInfo"] : new JobSeeker();
            JobSeeker js = new JobSeeker();
            Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();
            ProcessSelectJobSeeker jobSeeker = new ProcessSelectJobSeeker();
            jobSeeker.JobSeekerID = jobseekerID;
            jobSeeker.invoke();
            js = jobSeeker.JobSeeker != null ? jobSeeker.JobSeeker.Find(j => j.JobSeekerID == jobseekerID) : new JobSeeker();

            if (Session["UserID"] != null)
            {
                Page.Validate("valEducationalInfo");

                if (!Page.IsValid)
                    return;

                //Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();

                FormView fvEducationalInfo = (FormView)upEducationalInfo.FindControl("fvEducationalInfo");
                lblInsertMsg = (HtmlGenericControl)fvEducationalInfo.FindControl("lblInsertMsg");

                TextBox txtInstitution = (TextBox)fvEducationalInfo.FindControl("txtInstitution");
                TextBox txtSpecializedSubjeccts = (TextBox)fvEducationalInfo.FindControl("txtSpecializedSubjeccts");
                DropDownList ddlFieldOfStudy = (DropDownList)fvEducationalInfo.FindControl("ddlFieldOfStudy");
                TextBox txtDegree = (TextBox)fvEducationalInfo.FindControl("txtDegree");
                TextBox txtGrade = (TextBox)fvEducationalInfo.FindControl("txtGrade");
                TextBox txtEduStartDate = (TextBox)fvEducationalInfo.FindControl("txtEduStartDate");
                TextBox txtEduEndDate = (TextBox)fvEducationalInfo.FindControl("txtEduEndDate");


                long educationInfoID = 0;

                educationInfoID = fvEducationalInfo.DataKey["EducationInfoID"] != null ? long.Parse(fvEducationalInfo.DataKey["EducationInfoID"].ToString()) : 0;
                if (txtInstitution != null) educationInfo.InstitutionName = txtInstitution.Text.Trim();
                if (txtSpecializedSubjeccts != null) educationInfo.SpecializedSubjects = txtSpecializedSubjeccts.Text.Trim();
                if (ddlFieldOfStudy != null) educationInfo.FieldOfStudyID = ddlFieldOfStudy != null ? int.Parse(ddlFieldOfStudy.SelectedValue) : -1;
                if (txtDegree != null) educationInfo.Degree = txtDegree.Text.Trim();
                if (txtGrade != null) educationInfo.Grade = txtGrade.Text.Trim();
                if (txtEduStartDate != null) educationInfo.FromDate = DateTime.ParseExact(txtEduStartDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                if (txtEduEndDate != null) educationInfo.ToDate = DateTime.ParseExact(txtEduEndDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);


                educationInfo.IsDeleted = false;
                educationInfo.JobSeekerID = jobseekerID;

                lstEducationInfo = LoadEducationalInfo(js);

                if (lstEducationInfo != null && !lstEducationInfo.Exists(eu => eu.InstitutionName == txtInstitution.Text.Trim() && eu.Degree == txtDegree.Text.Trim()))
                {
                    lstEducationInfo.Add(educationInfo);

                    fvEducationalInfo.ChangeMode(FormViewMode.ReadOnly);

                    ProcessInsertJobSeekerEducationInfo educa = new ProcessInsertJobSeekerEducationInfo();
                    educationInfo.JobSeekerID = jobseekerID;
                    educa.EducationInfo = educationInfo;
                    educa.invoke();

                    if (educa.LastJobSeekerEducationInfoID > -1)
                    {
                        lblInsertMsg.Attributes.Add("style", "float:right;color: green;");
                        ScriptManager.RegisterStartupScript(this, GetType(), "ClearProfessoinalInfo", "ClearInfo('Entry inserted successfully','ctl00_MainContent_fvEducationalInfo_lblInsertMsg');", true);
                    }

                    fvProfessionalInfo.ChangeMode(FormViewMode.ReadOnly);

                    if (js != null)
                    {
                        BindEducationalInfo(js);
                    }
                }
                else
                {
                    lblInsertMsg.Visible = true;

                    if (lblInsertMsg != null)
                    {
                        lblInsertMsg.InnerText = "Already exists";
                        lblInsertMsg.Attributes.Add("style", "float:right;color: red;");
                    }
                }
            }
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }
    protected void fvEducationalInfo_ItemUpdating(object sender, FormViewUpdateEventArgs e)
    {
        HtmlGenericControl lblInsertMsg = null;
        JobSeeker jobseeker = new JobSeeker();
        lblSaveMsg.Text = string.Empty;
        try
        {
            //JobSeeker js = Session["CurrentJobSeekerInfo"] != null ? (JobSeeker)Session["CurrentJobSeekerInfo"] : new JobSeeker();
            JobSeeker js = new JobSeeker();
            Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();
            ProcessSelectJobSeeker jobSeeker = new ProcessSelectJobSeeker();
            jobSeeker.JobSeekerID = jobseekerID;
            jobSeeker.invoke();
            js = jobSeeker.JobSeeker != null ? jobSeeker.JobSeeker.Find(j => j.JobSeekerID == jobseekerID) : new JobSeeker();


            lblInsertMsg = (HtmlGenericControl)fvProfessionalInfo.FindControl("lblInsertMsg");

            if (Session["UserID"] != null)
            {
                Page.Validate("valEducationalInfo");

                if (!Page.IsValid)
                    return;


                //Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();

                TextBox txtInstitution = (TextBox)fvEducationalInfo.FindControl("txtInstitution");
                TextBox txtSpecializedSubjeccts = (TextBox)fvEducationalInfo.FindControl("txtSpecializedSubjeccts");
                DropDownList ddlFieldOfStudy = (DropDownList)fvEducationalInfo.FindControl("ddlFieldOfStudy");
                TextBox txtDegree = (TextBox)fvEducationalInfo.FindControl("txtDegree");
                TextBox txtGrade = (TextBox)fvEducationalInfo.FindControl("txtGrade");
                TextBox txtEduStartDate = (TextBox)fvEducationalInfo.FindControl("txtEduStartDate");
                TextBox txtEduEndDate = (TextBox)fvEducationalInfo.FindControl("txtEduEndDate");

                EducationInfo educationInfo = new EducationInfo();
                educationInfo.JobSeekerID = jobseekerID;

                List<EducationInfo> lstEducationInfo = LoadEducationalInfo(js);

                long educationInfoID = fvEducationalInfo.DataKey["EducationInfoID"] != null ? long.Parse(fvEducationalInfo.DataKey["EducationInfoID"].ToString()) : 0;

                EducationInfo ei = lstEducationInfo.Find(ee => ee.JobSeekerID == educationInfo.JobSeekerID && ee.EducationInfoID == educationInfoID);

                if (ei != null)
                {
                    if (txtInstitution != null) ei.InstitutionName = txtInstitution.Text.Trim();
                    if (txtSpecializedSubjeccts != null) ei.SpecializedSubjects = txtSpecializedSubjeccts.Text.Trim();
                    if (ddlFieldOfStudy != null) ei.FieldOfStudyID = ddlFieldOfStudy != null ? int.Parse(ddlFieldOfStudy.SelectedValue) : -1;
                    if (txtDegree != null) ei.Degree = txtDegree.Text.Trim();
                    if (txtGrade != null) ei.Grade = txtGrade.Text.Trim();
                    if (txtEduStartDate != null) ei.FromDate = DateTime.ParseExact(txtEduStartDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    if (txtEduEndDate != null) ei.ToDate = DateTime.ParseExact(txtEduEndDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);


                    ProcessInsertJobSeekerEducationInfo edu = new ProcessInsertJobSeekerEducationInfo();
                    ei.JobSeekerID = jobseekerID;
                    edu.EducationInfo = ei;
                    edu.invoke();

                    if (ei.EducationInfoID > -1)
                    {
                        lblInsertMsg.Attributes.Add("style", "float:right;color: green;");
                        ScriptManager.RegisterStartupScript(this, GetType(), "ClearEdcucationInfo", "ClearInfo('Entry updated successfully','ctl00_MainContent_fvEducationalInfo_lblInsertMsg');", true);
                    }

                    fvEducationalInfo.ChangeMode(FormViewMode.ReadOnly);

                    if (js != null)
                        BindEducationalInfo(js);
                }
            }
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }
    protected void fvEducationalInfo_DataBound(object sender, EventArgs e)
    {
        try
        {
            var drv = (nplJobsCommon.JobSeeker.EducationInfo)fvEducationalInfo.DataItem;

            if (drv != null)
            {
                DropDownList ddlFieldOfStudy = (DropDownList)fvEducationalInfo.FindControl("ddlFieldOfStudy");
                if (ddlFieldOfStudy != null)
                {
                    ListItem fieldofstudy = (ListItem)ddlFieldOfStudy.Items.FindByValue(drv.FieldOfStudyID.ToString());
                    if (fieldofstudy != null)
                    {
                        ((DropDownList)fvEducationalInfo.FindControl("ddlFieldOfStudy")).SelectedValue = drv.FieldOfStudyID.ToString();
                    }
                }
            }
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }

    protected void btnEducationInfoYes_Click(object sender, ImageClickEventArgs e)
    {
        if (Session["UserID"] != null)
        {
            EducationInfo educationInfo = new EducationInfo();
            educationInfo.JobSeekerID = Guid.Parse(HttpContext.Current.Session["UserID"].ToString());
            //Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();

            //JobSeeker js = Session["CurrentJobSeekerInfo"] != null ? (JobSeeker)Session["CurrentJobSeekerInfo"] : new JobSeeker();
            JobSeeker js = new JobSeeker();
            Guid jobseekerID = HttpContext.Current.Session["UserID"] != null ? Guid.Parse(HttpContext.Current.Session["UserID"].ToString()) : Guid.NewGuid();
            ProcessSelectJobSeeker jobSeeker = new ProcessSelectJobSeeker();
            jobSeeker.JobSeekerID = jobseekerID;
            jobSeeker.invoke();
            js = jobSeeker.JobSeeker != null ? jobSeeker.JobSeeker.Find(j => j.JobSeekerID == jobseekerID) : new JobSeeker();

            List<EducationInfo> lstEducationInfo = LoadEducationalInfo(js);

            if (lstEducationInfo != null && lstEducationInfo.Count > 0)
            {
                HiddenField hdEducationInfoID = fvEducationalInfo.FindControl("hdEducationInfoID") != null ? (HiddenField)fvEducationalInfo.FindControl("hdEducationInfoID") : null;
                long educationInfoID = hdEducationInfoID != null && !string.IsNullOrEmpty(hdEducationInfoID.Value) ? long.Parse(hdEducationInfoID.Value) : 0;
                EducationInfo edi = lstEducationInfo.Find(ei => ei.JobSeekerID == educationInfo.JobSeekerID && ei.EducationInfoID == educationInfoID);

                if (edi != null)
                {
                    lblEducationInfoText.InnerHtml = "Are you sure you want to delete ? <br/> " + edi.InstitutionName;

                    edi.IsDeleted = true;

                    DeleteJobSeekerEducationInfo dei = new DeleteJobSeekerEducationInfo();
                    dei.EducationInfoID = edi.EducationInfoID;
                    dei.invoke();
                    bool isDeleted = dei.isDeleted;

                    if (isDeleted)
                    {
                        lstEducationInfo.Remove(edi);
                        ModalPopupExtender2.Hide();
                        ScriptManager.RegisterStartupScript(this, GetType(), "ClearEducationalInfo", "ClearInfo('Entry deleted successfully','ctl00_MainContent_fvEducationalInfo_lblInsertMsg');", true);
                    }

                    if (HttpContext.Current.Session["UserID"] != null)
                    {
                        educationInfo.IsDeleted = true;
                        educationInfo.JobSeekerID = jobseekerID;

                        if (js != null)
                        {
                            BindEducationalInfo(js);
                        }
                    }


                    if (lstEducationInfo != null && lstEducationInfo.Count > 0)
                    {
                        fvEducationalInfo.ChangeMode(FormViewMode.ReadOnly);
                    }
                    else
                    {
                        fvEducationalInfo.ChangeMode(FormViewMode.Insert);
                        EductionInfoReloadInInsertMode(js);

                    }


                }
            }

        }
    }

    #endregion

    #region Load Inital DropDownLists

    /// <summary>
    ///This function loads nationality information
    /// </summary>
    #region  LoadNationality()
    public List<Nationality> LoadNationality()
    {
        List<Nationality> listNationality = new List<Nationality>();
        try
        {
            ProcessNationality nationalities = new ProcessNationality();
            nationalities.invoke();
            listNationality = nationalities.Nationality;


        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }

        return listNationality;
    }
    #endregion

    /// <summary>
    ///This function loads industry information
    /// </summary>
    #region  LoadIndustry()
    public List<Industry> LoadIndustry()
    {
        List<Industry> listIndustry = new List<Industry>();
        try
        {
            ProcessIndustry industries = new ProcessIndustry();
            industries.invoke();
            listIndustry = industries.Industry;
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }

        return listIndustry;
    }
    #endregion

    /// <summary>
    ///This function loads career level information
    /// </summary>
    #region  LoadCareerLevel()
    public void LoadCareerLevel()
    {
        try
        {
            ProcessCareerLevel carrerLevels = new ProcessCareerLevel();
            carrerLevels.invoke();
            if (fvProfessionalInfo.CurrentMode == FormViewMode.Edit)
            {
                DropDownList ddlCareerLevel = (DropDownList)fvProfessionalInfo.FindControl("ddlCareerLevel");
                ddlCareerLevel.DataTextField = "Level";
                ddlCareerLevel.DataValueField = "ID";
                ddlCareerLevel.DataSource = carrerLevels.CareerLevel;
            }
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }
    public List<CareerLevel> Load_CareerLevel()
    {
        List<CareerLevel> listCareerLevel = new List<CareerLevel>();
        try
        {
            ProcessCareerLevel carrerLevels = new ProcessCareerLevel();
            carrerLevels.invoke();
            listCareerLevel = carrerLevels.CareerLevel;
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }

        return listCareerLevel;
    }
    #endregion

    public void LoadDivision()
    {
        try
        {
            ProcessDivision division = new ProcessDivision();
            division.invoke();
            ddlDivision.DataSource = division.Divisions;
            ddlDivision.DataTextField = "Name";
            ddlDivision.DataValueField = "ID";
            ddlDivision.DataBind();

            ListItem l = new ListItem("--Select  a division--", "-1", true);
            l.Selected = true;
            ddlDivision.Items.Insert(0, l);

        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }

    }
    public void LoadDistrict()
    {
        try
        {
            ProcessDivision division = new ProcessDivision();
            division.invoke();
            ddlDivision.DataSource = division.Divisions;
            ddlDivision.DataTextField = "Name";
            ddlDivision.DataValueField = "ID";
            ddlDivision.DataBind();
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }
    public List<City> LoadCity()
    {
        List<City> listCity = new List<City>();
        try
        {
            ProcessSelectCity city = new ProcessSelectCity();
            city.DistrictID = ddlDistrict.SelectedValue != null ? int.Parse(ddlDistrict.SelectedValue.ToString()) : -1;
            city.GetCityByDistrict();
            listCity = city.City;
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }

        return listCity;
    }
    public void LoadCountry()
    {
        try
        {
            ProcessCountry country = new ProcessCountry();
            country.invoke();
            ddlCountry.DataSource = country.Country;
            ddlCountry.DataTextField = "Name";
            ddlCountry.DataValueField = "ID";
            ddlCountry.DataBind();


            ListItem l = new ListItem("--Select  a country--", "-1", true);
            l.Selected = true;
            ddlCountry.Items.Insert(0, l);
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }

    /// <summary>
    ///This function loads comapany size information
    /// </summary>
    #region  LoadEmployeeRange()
    public List<EmployeeRange> LoadEmployeeRange()
    {
        List<EmployeeRange> listEmployeeRange = new List<EmployeeRange>();
        try
        {
            ProcessEmployeeRange employeeRange = new ProcessEmployeeRange();
            employeeRange.invoke();
            listEmployeeRange = employeeRange.EmployeeRange;
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }

        return listEmployeeRange;
    }
    #endregion

    /// <summary>
    ///This function loads employeer type information
    /// </summary>
    #region  LoadEmployeerType()
    public List<EmployeerType> LoadEmployeerType()
    {
        List<EmployeerType> lstEmployeerType = new List<EmployeerType>();
        try
        {
            ProcessEmployeerType employeerType = new ProcessEmployeerType();
            employeerType.invoke();
            lstEmployeerType = employeerType.EmployeerType;
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
        return lstEmployeerType;
    }
    #endregion

    /// <summary>
    ///This function job type information
    /// </summary>
    #region  LoadJobType()
    public List<JobType> LoadJobType()
    {
        List<JobType> listJobType = new List<JobType>();
        try
        {
            ProcessJobType jobType = new ProcessJobType();
            jobType.invoke();
            listJobType = jobType.JobType;
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
        return listJobType;
    }
    #endregion

    /// <summary>
    ///This function loads language
    /// </summary>
    #region  LoadLanguage()
    public List<Language> LoadLanguage()
    {
        List<Language> listLanguage = new List<Language>();
        try
        {
            nplJobsBLL.Common.ProcessLanguage language = new nplJobsBLL.Common.ProcessLanguage();
            language.invoke();
            listLanguage = language.Language;
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
        return listLanguage;
    }
    #endregion

    /// <summary>
    ///This function loads salary range
    /// </summary>
    #region  LoadSalaryRange()
    public List<SalaryRange> LoadSalaryRange()
    {
        List<SalaryRange> listSalaryRange = new List<SalaryRange>();
        try
        {
            nplJobsBLL.Common.ProcessSalaryRange salaryRange = new nplJobsBLL.Common.ProcessSalaryRange();
            salaryRange.invoke();
            listSalaryRange = salaryRange.SalaryRange;
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
        return listSalaryRange;
    }
    #endregion

    /// <summary>
    ///This function loads gender information
    /// </summary>
    #region  LoadGender()
    public List<Gender> LoadGender()
    {
        List<Gender> listGender = new List<Gender>();
        try
        {
            ProcessGender gender = new ProcessGender();
            gender.invoke();
            listGender = gender.Gender;
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }

        return listGender;
    }
    #endregion


    /// <summary>
    ///This function loads field of study information
    /// </summary>
    #region  LoadFieldOfStudy()
    public List<FieldOfStudy> LoadFieldOfStudy()
    {
        List<FieldOfStudy> listFieldOfStudy = new List<FieldOfStudy>();
        try
        {
            ProcessFieldOfStudy fs = new ProcessFieldOfStudy();
            fs.invoke();
            listFieldOfStudy = fs.FieldOfStudy;
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }

        return listFieldOfStudy;
    }
    #endregion


    /// <summary>
    ///This function loads marital status
    /// </summary>
    #region  LoadMaritalStatus()
    public List<MaritalStatus> LoadMaritalStatus()
    {
        List<MaritalStatus> listMaritalStatus = new List<MaritalStatus>();
        try
        {
            ProcessMaritalStatus ms = new ProcessMaritalStatus();
            ms.invoke();
            listMaritalStatus = ms.MaritalStatus;

        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
        return listMaritalStatus;
    }
    #endregion


    #endregion

    #region AddRemove Qualification
    protected void btnAddQualification_Click(object sender, EventArgs e)
    {
        Page.Validate("valQualification");
        if (!Page.IsValid)
            return;

        divQualificationContainer1.Visible = true;

        if (!string.IsNullOrEmpty(txtQualification.Text))
        {
            TempQualification qt = new TempQualification();
            qt.QualificationID = 0;
            qt.Name = txtQualification.Text;

            if (Session["Qualification"] != null)
            {
                List<TempQualification> lstQua = (List<TempQualification>)Session["Qualification"];
                TempQualification q = lstQua.Find(r => r.QualificationID == qt.QualificationID);
                if (q != null)
                {
                    lstQua.Remove(q);
                }
                lstQua.Add(qt);
                Session["Qualification"] = lstQua;
            }
            else
            {
                List<TempQualification> lstQua = new List<TempQualification>();
                lstQua.Add(qt);
                Session["Qualification"] = lstQua;
            }
        }
        lblSaveMsg.Text = string.Empty;
    }
    protected void btnAddQualification1_Click(object sender, EventArgs e)
    {
        Page.Validate("valQualification");
        if (!Page.IsValid)
            return;

        divQualificationContainer2.Visible = true;

        if (!string.IsNullOrEmpty(txtQualification1.Text))
        {
            TempQualification qt = new TempQualification();
            qt.QualificationID = 1;
            qt.Name = txtQualification1.Text;

            if (Session["Qualification"] != null)
            {
                List<TempQualification> lstQua = (List<TempQualification>)Session["Qualification"];
                TempQualification q = lstQua.Find(r => r.QualificationID == qt.QualificationID);
                if (q != null)
                {
                    lstQua.Remove(q);
                }
                lstQua.Add(qt);
                Session["Qualification"] = lstQua;
            }
            else
            {
                List<TempQualification> lstQua = new List<TempQualification>();
                lstQua.Add(qt);
                Session["Qualification"] = lstQua;
            }
        }
        lblSaveMsg.Text = string.Empty;
    }
    protected void btnAddQualification2_Click(object sender, EventArgs e)
    {
        Page.Validate("valQualification");
        if (!Page.IsValid)
            return;
        divQualificationContainer3.Visible = true;
        if (!string.IsNullOrEmpty(txtQualification2.Text))
        {
            TempQualification qt = new TempQualification();
            qt.QualificationID = 2;
            qt.Name = txtQualification2.Text;

            if (Session["Qualification"] != null)
            {
                List<TempQualification> lstQua = (List<TempQualification>)Session["Qualification"];
                TempQualification q = lstQua.Find(r => r.QualificationID == qt.QualificationID);
                if (q != null)
                {
                    lstQua.Remove(q);
                }
                lstQua.Add(qt);
                Session["Qualification"] = lstQua;
            }
            else
            {
                List<TempQualification> lstQua = new List<TempQualification>();
                lstQua.Add(qt);
                Session["Qualification"] = lstQua;
            }
        }
        lblSaveMsg.Text = string.Empty;
    }
    protected void btnAddQualification3_Click(object sender, EventArgs e)
    {
        Page.Validate("valQualification");
        if (!Page.IsValid)
            return;

        divQualificationContainer4.Visible = true;
        if (!string.IsNullOrEmpty(txtQualification3.Text))
        {
            TempQualification qt = new TempQualification();
            qt.QualificationID = 3;
            qt.Name = txtQualification3.Text;

            if (Session["Qualification"] != null)
            {
                List<TempQualification> lstQua = (List<TempQualification>)Session["Qualification"];
                TempQualification q = lstQua.Find(r => r.QualificationID == qt.QualificationID);
                if (q != null)
                {
                    lstQua.Remove(q);
                }
                lstQua.Add(qt);
                Session["Qualification"] = lstQua;
            }
            else
            {
                List<TempQualification> lstQua = new List<TempQualification>();
                lstQua.Add(qt);
                Session["Qualification"] = lstQua;
            }
        }
        lblSaveMsg.Text = string.Empty;
    }
    protected void txtQualification4_TextChanged(object sender, EventArgs e)
    {

        Page.Validate("valQualification");
        if (!Page.IsValid)
            return;

        if (!string.IsNullOrEmpty(txtQualification4.Text))
        {
            TempQualification qt = new TempQualification();
            qt.QualificationID = 4;
            qt.Name = txtQualification4.Text;

            if (Session["Qualification"] != null)
            {
                List<TempQualification> lstQua = (List<TempQualification>)Session["Qualification"];
                TempQualification q = lstQua.Find(r => r.QualificationID == qt.QualificationID);
                if (q != null)
                {
                    lstQua.Remove(q);
                }
                lstQua.Add(qt);
                Session["Qualification"] = lstQua;
            }
            else
            {
                List<TempQualification> lstQua = new List<TempQualification>();
                lstQua.Add(qt);
                Session["Qualification"] = lstQua;
            }
        }
        lblSaveMsg.Text = string.Empty;
    }
    protected void btnRemoveQualification1_Click(object sender, EventArgs e)
    {
        divQualificationContainer1.Visible = false;
        txtQualification1.Text = string.Empty;

        TempQualification qt = new TempQualification();
        qt.QualificationID = 1;

        if (Session["Qualification"] != null)
        {
            List<TempQualification> lstQua = (List<TempQualification>)Session["Qualification"];
            TempQualification q = lstQua.Find(r => r.QualificationID == qt.QualificationID);
            if (q != null)
            {
                lstQua.Remove(q);
                Session["Qualification"] = lstQua;
            }
        }
        lblSaveMsg.Text = string.Empty;

    }
    protected void btnRemoveQualification2_Click(object sender, EventArgs e)
    {
        divQualificationContainer2.Visible = false;
        txtQualification2.Text = string.Empty;

        TempQualification qt = new TempQualification();
        qt.QualificationID = 2;

        if (Session["Qualification"] != null)
        {
            List<TempQualification> lstQua = (List<TempQualification>)Session["Qualification"];
            TempQualification q = lstQua.Find(r => r.QualificationID == qt.QualificationID);
            if (q != null)
            {
                lstQua.Remove(q);
                Session["Qualification"] = lstQua;
            }
        }
        lblSaveMsg.Text = string.Empty;
    }
    protected void btnRemoveQualification3_Click(object sender, EventArgs e)
    {
        divQualificationContainer3.Visible = false;
        txtQualification3.Text = string.Empty;


        TempQualification qt = new TempQualification();
        qt.QualificationID = 3;

        if (Session["Qualification"] != null)
        {
            List<TempQualification> lstQua = (List<TempQualification>)Session["Qualification"];
            TempQualification q = lstQua.Find(r => r.QualificationID == qt.QualificationID);
            if (q != null)
            {
                lstQua.Remove(q);
                Session["Qualification"] = lstQua;
            }
        }
        lblSaveMsg.Text = string.Empty;
    }
    protected void btnRemoveQualification4_Click(object sender, EventArgs e)
    {
        divQualificationContainer4.Visible = false;
        txtQualification4.Text = string.Empty;



        TempQualification qt = new TempQualification();
        qt.QualificationID = 4;

        if (Session["Qualification"] != null)
        {
            List<TempQualification> lstQua = (List<TempQualification>)Session["Qualification"];
            TempQualification q = lstQua.Find(r => r.QualificationID == qt.QualificationID);
            if (q != null)
            {
                lstQua.Remove(q);
                Session["Qualification"] = lstQua;
            }
        }
        lblSaveMsg.Text = string.Empty;
    }

    #endregion

    #region AddRemove Language
    protected void btnAddOtherLanguage_Click(object sender, ImageClickEventArgs e)
    {
        Control languageContainer1 = upLanguage.FindControl("languageContainer1");
        languageContainer1.Visible = true;

        DropDownList ddlOtherLanguage1 = (DropDownList)upLanguage.FindControl("ddlOtherLanguage1");
        ddlOtherLanguage1.SelectedValue = "-1";

        DropDownList ddlFluency1 = (DropDownList)upLanguage.FindControl("ddlFluency1");
        ddlFluency1.SelectedValue = "-1";
        lblSaveMsg.Text = string.Empty;
    }
    protected void btnAddOtherLanguage2_Click(object sender, ImageClickEventArgs e)
    {
        Control languageContainer3 = upLanguage.FindControl("languageContainer3");
        languageContainer3.Visible = true;

        DropDownList ddlOtherLanguage3 = (DropDownList)upLanguage.FindControl("ddlOtherLanguage3");
        ddlOtherLanguage3.SelectedValue = "-1";

        DropDownList ddlFluency3 = (DropDownList)upLanguage.FindControl("ddlFluency3");
        ddlFluency3.SelectedValue = "-1";

        lblSaveMsg.Text = string.Empty;
    }
    protected void btnAddOtherLanguage3_Click(object sender, ImageClickEventArgs e)
    {
        DropDownList ddlOtherLanguage4 = (DropDownList)upLanguage.FindControl("ddlOtherLanguage4");
        ddlOtherLanguage4.SelectedValue = "-1";

        DropDownList ddlFluency4 = (DropDownList)upLanguage.FindControl("ddlFluency4");
        ddlFluency4.SelectedValue = "-1";

        Control languageContainer4 = upLanguage.FindControl("languageContainer4");
        languageContainer4.Visible = true;
        lblSaveMsg.Text = string.Empty;
    }
    protected void btnAddOtherLanguage1_Click(object sender, ImageClickEventArgs e)
    {
        Control languageContainer2 = upLanguage.FindControl("languageContainer2");
        languageContainer2.Visible = true;

        DropDownList ddlOtherLanguage2 = (DropDownList)upLanguage.FindControl("ddlOtherLanguage2");
        ddlOtherLanguage2.SelectedValue = "-1";

        DropDownList ddlFluency2 = (DropDownList)upLanguage.FindControl("ddlFluency2");
        ddlFluency2.SelectedValue = "-1";

        lblSaveMsg.Text = string.Empty;
    }

    protected void btnRemoveOtherLanguage1_Click(object sender, ImageClickEventArgs e)
    {
        DropDownList ddlOtherLanguage1 = (DropDownList)upLanguage.FindControl("ddlOtherLanguage1");
        ddlOtherLanguage1.SelectedValue = "-1";

        DropDownList ddlFluency1 = (DropDownList)upLanguage.FindControl("ddlFluency1");
        ddlFluency1.SelectedValue = "-1";

        Control languageContainer1 = upLanguage.FindControl("languageContainer1");
        languageContainer1.Visible = false;

        lblSaveMsg.Text = string.Empty;
    }
    protected void btnRemoveOtherLanguage2_Click(object sender, ImageClickEventArgs e)
    {
        DropDownList ddlOtherLanguage2 = (DropDownList)upLanguage.FindControl("ddlOtherLanguage2");
        ddlOtherLanguage2.SelectedValue = "-1";

        DropDownList ddlFluency2 = (DropDownList)upLanguage.FindControl("ddlFluency2");
        ddlFluency2.SelectedValue = "-1";

        Control languageContainer2 = upLanguage.FindControl("languageContainer2");
        languageContainer2.Visible = false;
        lblSaveMsg.Text = string.Empty;
    }
    protected void btnRemoveOtherLanguage3_Click(object sender, ImageClickEventArgs e)
    {
        DropDownList ddlOtherLanguage3 = (DropDownList)upLanguage.FindControl("ddlOtherLanguage3");
        ddlOtherLanguage3.SelectedValue = "-1";

        DropDownList ddlFluency3 = (DropDownList)upLanguage.FindControl("ddlFluency3");
        ddlFluency3.SelectedValue = "-1";

        Control languageContainer3 = upLanguage.FindControl("languageContainer3");
        languageContainer3.Visible = false;
        lblSaveMsg.Text = string.Empty;
    }
    protected void btnRemoveOtherLanguage4_Click(object sender, ImageClickEventArgs e)
    {
        DropDownList ddlOtherLanguage4 = (DropDownList)upLanguage.FindControl("ddlOtherLanguage4");
        ddlOtherLanguage4.SelectedValue = "-1";

        DropDownList ddlFluency4 = (DropDownList)upLanguage.FindControl("ddlFluency4");
        ddlFluency4.SelectedValue = "-1";

        Control languageContainer4 = upLanguage.FindControl("languageContainer4");
        languageContainer4.Visible = false;
        lblSaveMsg.Text = string.Empty;
    }


    #endregion

    #region Division And City
    protected void ddlDivision_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            int id = ddlDivision.SelectedValue != null ? int.Parse(ddlDivision.SelectedValue.ToString()) : -1;
            PopulateDistrict(id);
        }
        catch (Exception exp)
        {
            throw new Exception(exp.Message.ToString());
        }
    }
    private void PopulateDistrict(int divisionID)
    {
        ProcessDistrict district = new ProcessDistrict();

        try
        {

            district.DivisionId = divisionID;
            district.invoke();

            if (district.Districts != null && district.Districts.Count > 0)
            {
                if (ddlDistrict.Items.Count > 0)
                    ddlDistrict.Items.Clear();

                ddlDistrict.DataSource = district.Districts;
                ddlDistrict.DataTextField = "Name";
                ddlDistrict.DataValueField = "ID";
                ddlDistrict.DataBind();

                if (ddlDistrict.Items.FindByValue("-1") == null)
                {
                    ListItem l = new ListItem("--Select  a district--", "-1", true);
                    ddlDistrict.Items.Insert(0, l);
                }
                if (ddlCity.Items.Count > 0)
                {
                    int id = ddlDistrict.SelectedValue != null ? int.Parse(ddlDistrict.SelectedValue.ToString()) : -1;
                    PopulateCity(id);
                }
            }
            else
            {
                ddlDistrict.ClearSelection();

                if (ddlCity.Items.Count > 0)
                    ddlCity.ClearSelection();
            }
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }
    protected void ddlDistrict_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            int id = ddlDistrict.SelectedValue != null ? int.Parse(ddlDistrict.SelectedValue.ToString()) : -1;
            PopulateCity(id);
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }
    private void PopulateCity(int districtID)
    {

        ProcessSelectCity city = new ProcessSelectCity();
        try
        {


            city.DistrictID = districtID;
            city.GetCityByDistrict();

            if (city.City != null && city.City.Count > 0)
            {
                if (ddlCity.Items.Count > 0)
                    ddlCity.Items.Clear();

                ddlCity.DataSource = city.City;
                ddlCity.DataTextField = "Name";
                ddlCity.DataValueField = "ID";
                ddlCity.DataBind();

                if (ddlCity.Items.FindByValue("-1") == null)
                {
                    ListItem l = new ListItem("--Select  a city--", "-1", true);
                    ddlCity.Items.Insert(0, l);
                }
            }
            else
            {
                if (ddlCity.Items.Count > 0)
                    ddlCity.ClearSelection();
            }
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }
    protected void ddlDistrict_DataBinding(object sender, EventArgs e)
    {
        if (ddlDistrict.Items.Count > 0)
        {
            if (ddlDistrict.SelectedValue == "")
            {
                ddlDistrict.SelectedIndex = 0;
                ddlCity.SelectedIndex = 0;
            }
            else if (ddlDistrict.SelectedValue == "-1")
            {
                ddlCity.SelectedValue = "-1";
            }
        }
    }
    protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {

            if (!ddlCountry.SelectedItem.Text.Equals("Nepal"))
            {
                ddlDivision.Enabled = false;
                ddlDistrict.Enabled = false;
                ddlCity.Enabled = false;

                ddlDivision.SelectedIndex = -1;
                ddlDistrict.SelectedIndex = -1;
                ddlCity.SelectedIndex = -1;

                if (ddlDivision.Items.Count > 0)
                {
                    ddlDivision.SelectedItem.Text = "";
                }
                if (ddlDistrict.Items.Count > 0)
                {
                    ddlDistrict.SelectedItem.Text = "";
                }
                if (ddlCity.Items.Count > 0)
                {
                    ddlCity.SelectedItem.Text = "";
                }
            }
            else
            {
                //LoadDivision();
                ddlDivision.SelectedIndex = -1;

                ListItem l = new ListItem("--Select  a division--", "-1", true);
                l.Selected = true;
                ddlDivision.Items.Insert(0, l);

                if (ddlDivision.Items.FindByText("") != null)
                {
                    ListItem l1 = ddlDivision.Items.FindByText("");
                    ddlDivision.Items.Remove(l1);
                }
                ddlDistrict.Items.Clear();
                ddlCity.Items.Clear();

                ddlDivision.Enabled = true;
                ddlDistrict.Enabled = true;
                ddlCity.Enabled = true;
            }

            lstSkills = hdnSelectedTags.Value != null ? hdnSelectedTags.Value.ToString().Split(new char[] { ',' }).ToList() : null; ;
            lblSaveMsg.Text = string.Empty;
        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }
    #endregion

    #region AddJobSeeker
    /// <summary>
    /// This function adds a job seeker
    /// </summary>
    private void AddJobSeeker()
    {
        lblOtherLanguageCheck.Visible = false;
        ProcessInsertJobSeeker insertJobSeeker = new ProcessInsertJobSeeker();
        try
        {
            Guid jobseekerID;

            JobSeeker jobSeeker = new JobSeeker();

            if (HttpContext.Current.Session["UserID"] != null)
                jobseekerID = Guid.Parse(HttpContext.Current.Session["UserID"].ToString());
            else
                jobseekerID = Guid.Empty;

            jobSeeker.JobSeekerID = jobseekerID;
            jobSeeker.FirstName = !String.IsNullOrEmpty(txtFirstName.Text) ? txtFirstName.Text.Trim() : String.Empty;
            jobSeeker.LastName = !String.IsNullOrEmpty(txtLastName.Text) ? txtLastName.Text.Trim() : String.Empty;
            string dt = String.Format("{0:MM/dd/yyyy}", txtDateOfBirth.Text);


            string[] dates = !String.IsNullOrEmpty(txtDateOfBirth.Text) ? txtDateOfBirth.Text.Split(new char[] { '/' }) : null;
            DateTime _dt = dates != null ? DateTime.ParseExact(txtDateOfBirth.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture) : DateTime.Now;

            jobSeeker.DOB = _dt;
            jobSeeker.NationalityID = !String.IsNullOrEmpty(ddlNationality.SelectedValue) ? int.Parse(ddlNationality.SelectedValue) : -1;
            jobSeeker.AboutMe = !String.IsNullOrEmpty(txtAboutMe.Text) ? txtAboutMe.Text.Trim() : String.Empty;
            jobSeeker.GenderID = !String.IsNullOrEmpty(ddlGender.SelectedValue) ? int.Parse(ddlGender.SelectedValue) : -1;
            jobSeeker.MaritalStatusID = !String.IsNullOrEmpty(ddlMaritalStatus.SelectedValue) ? int.Parse(ddlMaritalStatus.SelectedValue) : -1;

            jobSeeker.Email = !String.IsNullOrEmpty(txtEmail.Text) ? txtEmail.Text.Trim() : String.Empty;
            jobSeeker.AlternativeEmail = !String.IsNullOrEmpty(txtAleternativeEmail.Text) ? txtAleternativeEmail.Text.Trim() : String.Empty;
            jobSeeker.PostalAddress = !String.IsNullOrEmpty(txtPostalAddress.Text) ? txtPostalAddress.Text.Trim() : String.Empty;

            jobSeeker.CountryID = !String.IsNullOrEmpty(ddlCountry.SelectedValue) ? int.Parse(ddlCountry.SelectedValue) : -1;
            jobSeeker.DivisionID = !String.IsNullOrEmpty(ddlDivision.SelectedValue) ? int.Parse(ddlDivision.SelectedValue) : -1;
            jobSeeker.DistrictID = !String.IsNullOrEmpty(ddlDistrict.SelectedValue) ? int.Parse(ddlDistrict.SelectedValue) : -1;
            jobSeeker.CityID = !String.IsNullOrEmpty(ddlCity.SelectedValue) ? int.Parse(ddlCity.SelectedValue) : -1;

            // jobSeeker.PermanentAddress = !String.IsNullOrEmpty(txtPermenantAddress.Text) ? txtPermenantAddress.Text.Trim() : String.Empty;
            jobSeeker.PresentSalaryID = !String.IsNullOrEmpty(ddlPresentSalary.SelectedValue) ? int.Parse(ddlPresentSalary.SelectedValue) : -1;
            jobSeeker.ExpectedSalaryID = !String.IsNullOrEmpty(ddlExpectedSalary.SelectedValue) ? int.Parse(ddlExpectedSalary.SelectedValue) : -1;
            jobSeeker.HomePhone = !String.IsNullOrEmpty(txtHomePhone.Text) ? txtHomePhone.Text.Trim() : String.Empty;
            jobSeeker.MobilePhone = !String.IsNullOrEmpty(txtMobilePhone.Text) ? txtMobilePhone.Text.Trim() : String.Empty;
            jobSeeker.Resume = Session["UploadedResume"] != null ? Session["UploadedResume"].ToString() : String.Empty;
            jobSeeker.Photo = Session["UploadedImage"] != null ? Session["UploadedImage"].ToString() : String.Empty;

            if (Session["Qualification"] != null)
            {
                jobSeeker.Qualifications = GetQulification();
                //jobSeeker.Qualifications = Session["Qualification"] != null ? string.Join("~", quali) : string.Empty;
            }
            else
            {
                if (!string.IsNullOrEmpty(txtQualification.Text))
                {
                    TempQualification qt = new TempQualification();
                    qt.QualificationID = 0;
                    qt.Name = txtQualification.Text;

                    if (Session["Qualification"] != null)
                    {
                        List<TempQualification> lstQua = (List<TempQualification>)Session["Qualification"];
                        TempQualification q = lstQua.Find(r => r.QualificationID == qt.QualificationID);
                        if (q != null)
                        {
                            lstQua.Remove(q);
                        }
                        lstQua.Add(qt);
                        Session["Qualification"] = lstQua;
                    }
                    else
                    {
                        List<TempQualification> lstQua = new List<TempQualification>();
                        lstQua.Add(qt);
                        Session["Qualification"] = lstQua;
                    }
                }
                jobSeeker.Qualifications = Session["Qualification"] != null ? GetQulification() : string.Empty;
            }
            jobSeeker.Skills = hdnSelectedTags.Value;

            insertJobSeeker.JobSeeker = jobSeeker;

            List<JobSeekerLanguageProficiency> proficienciesToRemove = new List<JobSeekerLanguageProficiency>();
            List<JobSeekerLanguageProficiency> proficiencies = new List<JobSeekerLanguageProficiency>();
            proficiencies = GetLanguage(jobseekerID, proficienciesToRemove);

            int tmpLanguageID = 0;

            lblOtherLanguageCheck.Visible = false;
            lblOtherLanguageCheck.Text = string.Empty;

            foreach (var p in proficiencies)
            {
                if (tmpLanguageID == p.LanguageID)
                {
                    lblOtherLanguageCheck.Text = "1";
                    cusCustom.Validate();
                    return;
                }

                tmpLanguageID = p.LanguageID;
            }


            string ss = divOtherLanguagesContainer1.Controls.Count.ToString();


            if (proficiencies != null)
            {
                if (Session["CurrentLanguages"] != null)
                {
                    List<JobSeekerLanguageProficiency> lstCurrentLanguages = (List<JobSeekerLanguageProficiency>)Session["CurrentLanguages"];

                    int lastProficiencyID = 0;

                    var list = new List<JobSeekerLanguageProficiency>();
                    JobSeekerLanguageProficiency lp;
                    foreach (var p in proficiencies)
                    {
                        int currentLanguageID = 0;

                        if (lstCurrentLanguages.Exists(cl => cl.ID == p.ID))
                            currentLanguageID = lstCurrentLanguages.Find(cl => cl.ID == p.ID).LanguageID;

                        ProcessInsertJobSeekerLanguageProficiencies jslpInsert = new ProcessInsertJobSeekerLanguageProficiencies();

                        if (p.LanguageID != currentLanguageID && currentLanguageID != 0)
                            p.CurrentLanguageID = currentLanguageID;
                        else
                            p.CurrentLanguageID = p.LanguageID;

                        jslpInsert.JobSeekerLanguageProficiency = p;
                        string ids = p.LanguageID.ToString() + "-" + p.ProficiencyID.ToString();

                        if (p.CurrentLanguageID == -1 && p.ProficiencyID == -1 && p.LanguageID == -1)
                        {
                        }
                        else
                        {
                            lp = new JobSeekerLanguageProficiency();
                            lp.Language = p.Language;
                            lp.Proficiency = p.Proficiency;
                            list.Add(lp);
                            jslpInsert.invoke();
                            lastProficiencyID = jslpInsert.LastProficiencyID;
                        }
                    }
                    Session["Languages"] = list;
                }
            }

            insertJobSeeker.invoke();


            lblSaveMsg.ForeColor = Color.Green;
            lblSaveMsg.Text = "Data saved successfully";
            Session["UploadedImage"] = null;
            Session["UploadedResume"] = null;
            //SaveLastUpdateTime(jobSeeker.JobSeekerID);

            jobSeeker.ProfessionalInfoID = -1;
            LoadProfessionalInfo(jobSeeker);

            jobSeeker.EducationInfoID -= -1;
            LoadEducationalInfo(jobSeeker);

        }
        catch (Exception ex)
        {
            lblSaveMsg.ForeColor = Color.Red;
            lblSaveMsg.Text = "Failed to save data";
            ErrorSignal.FromCurrentContext().Raise(ex);
        }

        ScriptManager.RegisterStartupScript(this, GetType(), "ClearSaveMsg", "ClearSaveMsg();", true);

    }

    private void SaveLastUpdateTime(Guid jobSeekerID)
    {
        try
        {
            JobSeeker js = new JobSeeker();
            js.JobSeekerID = jobSeekerID;

            ProcessInsertJobSeekerLastUpdate insert = new ProcessInsertJobSeekerLastUpdate();
            insert.JobSeeker = js;
            insert.invoke();

        }
        catch (Exception ex)
        {
            ErrorSignal.FromCurrentContext().Raise(ex);
        }
    }

    private string GetQulification()
    {
        string qualifications = string.Empty;

        if (!string.IsNullOrEmpty(txtQualification.Text))
        {
            qualifications = qualifications + txtQualification.Text.Trim() + "~";
        }
        if (!string.IsNullOrEmpty(txtQualification1.Text))
        {
            qualifications = qualifications + txtQualification1.Text.Trim() + "~";
        }
        if (!string.IsNullOrEmpty(txtQualification2.Text))
        {
            qualifications = qualifications + txtQualification2.Text.Trim() + "~";
        }
        if (!string.IsNullOrEmpty(txtQualification3.Text))
        {
            qualifications = qualifications + txtQualification3.Text.Trim() + "~";
        }
        if (!string.IsNullOrEmpty(txtQualification4.Text))
        {
            qualifications = qualifications + txtQualification4.Text.Trim() + "~";
        }
        return qualifications;
    }

    private List<JobSeekerLanguageProficiency> GetLanguage(Guid jobseekerID, List<JobSeekerLanguageProficiency> proficienciesToRemove)
    {
        List<JobSeekerLanguageProficiency> proficiencies = new List<JobSeekerLanguageProficiency>();

        JobSeekerLanguageProficiency jlp = new JobSeekerLanguageProficiency();

        jlp = new JobSeekerLanguageProficiency();
        jlp.LanguageID = 1;
        jlp.ProficiencyID = ddlNepali.SelectedValue != null ? int.Parse(ddlNepali.SelectedValue.ToString()) : 0;
        jlp.ID = !String.IsNullOrEmpty(hdOtherLanIDNepali.Value) ? int.Parse(hdOtherLanIDNepali.Value) : 0;
        jlp.JobSeekerID = jobseekerID;
        proficiencies.Add(jlp);

        jlp = new JobSeekerLanguageProficiency();
        jlp.LanguageID = 2;
        jlp.ProficiencyID = ddlEnglish.SelectedValue != null ? int.Parse(ddlEnglish.SelectedValue.ToString()) : 0;
        jlp.ID = !String.IsNullOrEmpty(hdOtherLanIDEnglish.Value) ? int.Parse(hdOtherLanIDEnglish.Value) : 0;
        jlp.JobSeekerID = jobseekerID;
        proficiencies.Add(jlp);

        if (languageContainer0.Visible)
        {
            jlp = new JobSeekerLanguageProficiency();
            jlp.JobSeekerID = jobseekerID;
            jlp.ID = !string.IsNullOrEmpty(hdOtherLanID0.Value) ? int.Parse(hdOtherLanID0.Value) : 0;
            jlp.LanguageID = ddlOtherLanguage0.SelectedValue != null ? int.Parse(ddlOtherLanguage0.SelectedValue.ToString()) : -1;
            jlp.ProficiencyID = ddlFluency0.SelectedValue != null ? int.Parse(ddlFluency0.SelectedValue.ToString()) : -1;
            proficiencies.Add(jlp);
        }
        else
        {
            if (!String.IsNullOrEmpty(hdOtherLanID0.Value))
            {
                if (int.Parse(hdOtherLanID0.Value) > 0)
                {
                    jlp = new JobSeekerLanguageProficiency();
                    jlp.JobSeekerID = jobseekerID;
                    jlp.ID = !string.IsNullOrEmpty(hdOtherLanID0.Value) ? int.Parse(hdOtherLanID0.Value) : 0;
                    jlp.LanguageID = ddlOtherLanguage0.SelectedValue != null ? int.Parse(ddlOtherLanguage0.SelectedValue.ToString()) : -1;
                    jlp.ProficiencyID = ddlFluency0.SelectedValue != null ? int.Parse(ddlFluency0.SelectedValue.ToString()) : -1;
                    proficienciesToRemove.Add(jlp);
                }
            }

        }
        if (languageContainer1.Visible)
        {
            jlp = new JobSeekerLanguageProficiency();
            jlp.JobSeekerID = jobseekerID;
            jlp.ID = !string.IsNullOrEmpty(hdOtherLanID1.Value) ? int.Parse(hdOtherLanID1.Value) : 0;
            jlp.LanguageID = ddlOtherLanguage1.SelectedValue != null ? int.Parse(ddlOtherLanguage1.SelectedValue.ToString()) : -1;
            jlp.ProficiencyID = ddlFluency1.SelectedValue != null ? int.Parse(ddlFluency1.SelectedValue.ToString()) : -1;
            proficiencies.Add(jlp);
        }
        else
        {
            if (!String.IsNullOrEmpty(hdOtherLanID1.Value))
            {
                if (int.Parse(hdOtherLanID1.Value) > 0)
                {
                    jlp = new JobSeekerLanguageProficiency();
                    jlp.JobSeekerID = jobseekerID;
                    jlp.ID = !string.IsNullOrEmpty(hdOtherLanID1.Value) ? int.Parse(hdOtherLanID1.Value) : 0;
                    jlp.LanguageID = ddlOtherLanguage1.SelectedValue != null ? int.Parse(ddlOtherLanguage1.SelectedValue.ToString()) : -1;
                    jlp.ProficiencyID = ddlFluency1.SelectedValue != null ? int.Parse(ddlFluency1.SelectedValue.ToString()) : -1;
                    proficienciesToRemove.Add(jlp);
                }
            }

        }
        if (languageContainer2.Visible)
        {
            jlp = new JobSeekerLanguageProficiency();
            jlp.JobSeekerID = jobseekerID;
            jlp.ID = !string.IsNullOrEmpty(hdOtherLanID2.Value) ? int.Parse(hdOtherLanID2.Value) : 0;
            jlp.LanguageID = ddlOtherLanguage2.SelectedValue != null ? int.Parse(ddlOtherLanguage2.SelectedValue.ToString()) : -1;
            jlp.ProficiencyID = ddlFluency2.SelectedValue != null ? int.Parse(ddlFluency2.SelectedValue.ToString()) : -1;
            proficiencies.Add(jlp);
        }
        else
        {
            if (!String.IsNullOrEmpty(hdOtherLanID2.Value))
            {
                if (int.Parse(hdOtherLanID2.Value) > 0)
                {
                    jlp = new JobSeekerLanguageProficiency();
                    jlp.JobSeekerID = jobseekerID;
                    jlp.ID = !string.IsNullOrEmpty(hdOtherLanID2.Value) ? int.Parse(hdOtherLanID2.Value) : 0;
                    jlp.LanguageID = ddlOtherLanguage2.SelectedValue != null ? int.Parse(ddlOtherLanguage2.SelectedValue.ToString()) : -1;
                    jlp.ProficiencyID = ddlFluency2.SelectedValue != null ? int.Parse(ddlFluency2.SelectedValue.ToString()) : -1;
                    proficienciesToRemove.Add(jlp);
                }
            }
        }
        if (languageContainer3.Visible)
        {
            jlp = new JobSeekerLanguageProficiency();
            jlp.JobSeekerID = jobseekerID;
            jlp.ID = hdOtherLanID3.Value != null ? int.Parse(hdOtherLanID3.Value) : 0;
            jlp.LanguageID = !string.IsNullOrEmpty(ddlOtherLanguage3.SelectedValue) ? int.Parse(ddlOtherLanguage3.SelectedValue.ToString()) : -1;
            jlp.ProficiencyID = ddlFluency3.SelectedValue != null ? int.Parse(ddlFluency3.SelectedValue.ToString()) : -1;
            proficiencies.Add(jlp);
        }
        else
        {
            if (!String.IsNullOrEmpty(hdOtherLanID3.Value))
            {
                if (int.Parse(hdOtherLanID3.Value) > 0)
                {
                    jlp = new JobSeekerLanguageProficiency();
                    jlp.JobSeekerID = jobseekerID;
                    jlp.ID = hdOtherLanID3.Value != null ? int.Parse(hdOtherLanID3.Value) : 0;
                    jlp.LanguageID = !string.IsNullOrEmpty(ddlOtherLanguage3.SelectedValue) ? int.Parse(ddlOtherLanguage3.SelectedValue.ToString()) : -1;
                    jlp.ProficiencyID = ddlFluency3.SelectedValue != null ? int.Parse(ddlFluency3.SelectedValue.ToString()) : -1;
                    proficienciesToRemove.Add(jlp);
                }
            }
        }
        if (languageContainer4.Visible)
        {
            jlp = new JobSeekerLanguageProficiency();
            jlp.JobSeekerID = jobseekerID;
            jlp.ID = !string.IsNullOrEmpty(hdOtherLanID4.Value) ? int.Parse(hdOtherLanID4.Value) : 0;
            jlp.LanguageID = ddlOtherLanguage4.SelectedValue != null ? int.Parse(ddlOtherLanguage4.SelectedValue.ToString()) : -1;
            jlp.ProficiencyID = ddlFluency4.SelectedValue != null ? int.Parse(ddlFluency4.SelectedValue.ToString()) : -1;
            proficiencies.Add(jlp);
        }
        else
        {
            if (!String.IsNullOrEmpty(hdOtherLanID4.Value))
            {
                if (int.Parse(hdOtherLanID4.Value) > 0)
                {
                    jlp = new JobSeekerLanguageProficiency();
                    jlp.JobSeekerID = jobseekerID;
                    jlp.ID = !string.IsNullOrEmpty(hdOtherLanID4.Value) ? int.Parse(hdOtherLanID4.Value) : 0;
                    jlp.LanguageID = ddlOtherLanguage4.SelectedValue != null ? int.Parse(ddlOtherLanguage4.SelectedValue.ToString()) : -1;
                    jlp.ProficiencyID = ddlFluency4.SelectedValue != null ? int.Parse(ddlFluency4.SelectedValue.ToString()) : -1;
                    proficienciesToRemove.Add(jlp);
                }
            }
        }

        if (proficienciesToRemove != null)
        {
            bool lastProficiencyID = false;
            foreach (var p in proficienciesToRemove)
            {
                ProcessDeleteJobSeekerLanguageProficiencies jslpDelete = new ProcessDeleteJobSeekerLanguageProficiencies();
                jslpDelete.JobSeekerLanguageProficiency = p;
                string ids = p.LanguageID.ToString() + "-" + p.ProficiencyID.ToString();
                jslpDelete.invoke();
                lastProficiencyID = jslpDelete.LastProficiencyID;
            }

        }
        return proficiencies;
    }
    #endregion

    #region WebMethod
    [WebMethod]
    public static List<string> LoadSkill()
    {
        List<string> skills = new List<string>();

        bool count = lstSkills != null && lstSkills.All(x => x == "");

        if (lstSkills != null && !count)
        {
            lstSkills.Sort();
           skills = lstSkills;
        }
        else
        {
            skills.Add("No data");
        }

        return skills;
    }

    [WebMethod]
    public static string LoadProfilePicPath()
    {
        string lp = HttpContext.Current.Session["UploadedImage"] != null ? HttpContext.Current.Session["UploadedImage"].ToString() : null;
        return lp != null ? lp : string.Empty;
    }
    #endregion

    protected void cusCustom_ServerValidate(object sender, ServerValidateEventArgs e)
    {
        if (e.Value == string.Empty)
        {
            e.IsValid = true;
        }
        else
        {
            e.IsValid = false;
            lblOtherLanguageCheck.Text = "";
        }
    }
    protected void custValDivision_ServerValidate(object sender, ServerValidateEventArgs e)
    {
        if (ddlCountry.Items[ddlCountry.SelectedIndex].Text.ToLower() == "nepal")
        {
            if (e.Value == "-1")
            {
                e.IsValid = false;
            }
            else
            {
                e.IsValid = true;
            }
        }
    }
    protected void custValDistrict_ServerValidate(object sender, ServerValidateEventArgs e)
    {
        if (ddlCountry.Items[ddlCountry.SelectedIndex].Text.ToLower() == "nepal")
        {
            if (e.Value == "-1")
            {
                e.IsValid = false;
            }
            else
            {
                e.IsValid = true;
            }
        }
    }
    protected void custValCity_ServerValidate(object sender, ServerValidateEventArgs e)
    {
        if (ddlCountry.Items[ddlCountry.SelectedIndex].Text.ToLower() == "nepal")
        {
            if (e.Value == "-1")
            {
                e.IsValid = false;
            }
            else
            {
                e.IsValid = true;
            }
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        lblSaveMsg.ForeColor = Color.Green;
        lblSaveMsg.Text = "";

        if (HttpContext.Current.Session["UserID"] != null)
        {
            Page.Validate("valSaveJobSeeker");


            if (!Page.IsValid)
            {
                //lblSelectDOB.Text = "Invalid date of birth";
                //lblSaveMsg.ForeColor = Color.Red;
                //lblSaveMsg.Text = "Invalid input data.Please enter correct data";
                return;
            }
            else
            {
                //lblSelectDOB.Text = string.Empty;
            }

            AddJobSeeker();
            LoadData();
        }
    }


    protected void custFluency0_ServerValidate(object source, ServerValidateEventArgs e)
    {
        if (e.Value != "-1")
        {
            e.IsValid = true;
        }
        else
        {
            e.IsValid = false;
        }

    }
}